~ubuntu-branches/ubuntu/feisty/wpasupplicant/feisty

« back to all changes in this revision

Viewing changes to ctrl_iface.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2007-04-01 10:53:37 UTC
  • Revision ID: james.westby@ubuntu.com-20070401105337-3dd89n3g8ecdhjsl
Tags: 0.5.7-0ubuntu2
Apply patch from upstream after private email discussion:
http://w1.fi/gitweb/gitweb.cgi?p=hostap.git;a=commitdiff;h=33673d3f43da6f5ec0f0aa5a8245a1617b6eb2fd#patch1
Fixes LP: #98895, #98925

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        char *value;
40
40
        int ret = 0;
41
41
 
42
 
        value = os_strchr(cmd, ' ');
 
42
        value = strchr(cmd, ' ');
43
43
        if (value == NULL)
44
44
                return -1;
45
45
        *value++ = '\0';
46
46
 
47
47
        wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
48
 
        if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
 
48
        if (strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
49
49
                eapol_sm_configure(wpa_s->eapol,
50
50
                                   atoi(value), -1, -1, -1);
51
 
        } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
 
51
        } else if (strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
52
52
                eapol_sm_configure(wpa_s->eapol,
53
53
                                   -1, atoi(value), -1, -1);
54
 
        } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
 
54
        } else if (strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
55
55
                eapol_sm_configure(wpa_s->eapol,
56
56
                                   -1, -1, atoi(value), -1);
57
 
        } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
 
57
        } else if (strcasecmp(cmd, "EAPOL::maxStart") == 0) {
58
58
                eapol_sm_configure(wpa_s->eapol,
59
59
                                   -1, -1, -1, atoi(value));
60
 
        } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
 
60
        } else if (strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
61
61
                if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
62
62
                                     atoi(value)))
63
63
                        ret = -1;
64
 
        } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
65
 
                   0) {
 
64
        } else if (strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") == 0) {
66
65
                if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
67
66
                                     atoi(value)))
68
67
                        ret = -1;
69
 
        } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
 
68
        } else if (strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
70
69
                if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
71
70
                        ret = -1;
72
71
        } else
96
95
}
97
96
 
98
97
 
 
98
#ifdef CONFIG_STAKEY
 
99
static int wpa_supplicant_ctrl_iface_stakey_request(
 
100
        struct wpa_supplicant *wpa_s, char *addr)
 
101
{
 
102
        u8 peer[ETH_ALEN];
 
103
 
 
104
        if (hwaddr_aton(addr, peer)) {
 
105
                wpa_printf(MSG_DEBUG, "CTRL_IFACE STAKEY-REQUEST: invalid "
 
106
                           "address '%s'", peer);
 
107
                return -1;
 
108
        }
 
109
 
 
110
        wpa_printf(MSG_DEBUG, "CTRL_IFACE STAKEY-REQUEST " MACSTR,
 
111
                   MAC2STR(peer));
 
112
 
 
113
        return wpa_sm_stakey_request(wpa_s->wpa, peer);
 
114
}
 
115
#endif /* CONFIG_STAKEY */
 
116
 
 
117
 
99
118
#ifdef CONFIG_PEERKEY
100
119
/* MLME-STKSTART.request(peer) */
101
120
static int wpa_supplicant_ctrl_iface_stkstart(
125
144
        int id;
126
145
        struct wpa_ssid *ssid;
127
146
 
128
 
        pos = os_strchr(rsp, '-');
 
147
        pos = strchr(rsp, '-');
129
148
        if (pos == NULL)
130
149
                return -1;
131
150
        *pos++ = '\0';
132
151
        id_pos = pos;
133
 
        pos = os_strchr(pos, ':');
 
152
        pos = strchr(pos, ':');
134
153
        if (pos == NULL)
135
154
                return -1;
136
155
        *pos++ = '\0';
137
156
        id = atoi(id_pos);
138
157
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
139
158
        wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
140
 
                              (u8 *) pos, os_strlen(pos));
 
159
                              (u8 *) pos, strlen(pos));
141
160
 
142
161
        ssid = wpa_config_get_network(wpa_s->conf, id);
143
162
        if (ssid == NULL) {
146
165
                return -1;
147
166
        }
148
167
 
149
 
        if (os_strcmp(rsp, "IDENTITY") == 0) {
150
 
                os_free(ssid->identity);
151
 
                ssid->identity = (u8 *) os_strdup(pos);
152
 
                ssid->identity_len = os_strlen(pos);
 
168
        if (strcmp(rsp, "IDENTITY") == 0) {
 
169
                free(ssid->identity);
 
170
                ssid->identity = (u8 *) strdup(pos);
 
171
                ssid->identity_len = strlen(pos);
153
172
                ssid->pending_req_identity = 0;
154
173
                if (ssid == wpa_s->current_ssid)
155
174
                        wpa_s->reassociate = 1;
156
 
        } else if (os_strcmp(rsp, "PASSWORD") == 0) {
157
 
                os_free(ssid->password);
158
 
                ssid->password = (u8 *) os_strdup(pos);
159
 
                ssid->password_len = os_strlen(pos);
 
175
        } else if (strcmp(rsp, "PASSWORD") == 0) {
 
176
                free(ssid->password);
 
177
                ssid->password = (u8 *) strdup(pos);
 
178
                ssid->password_len = strlen(pos);
160
179
                ssid->pending_req_password = 0;
161
180
                if (ssid == wpa_s->current_ssid)
162
181
                        wpa_s->reassociate = 1;
163
 
        } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
164
 
                os_free(ssid->new_password);
165
 
                ssid->new_password = (u8 *) os_strdup(pos);
166
 
                ssid->new_password_len = os_strlen(pos);
 
182
        } else if (strcmp(rsp, "NEW_PASSWORD") == 0) {
 
183
                free(ssid->new_password);
 
184
                ssid->new_password = (u8 *) strdup(pos);
 
185
                ssid->new_password_len = strlen(pos);
167
186
                ssid->pending_req_new_password = 0;
168
187
                if (ssid == wpa_s->current_ssid)
169
188
                        wpa_s->reassociate = 1;
170
 
        } else if (os_strcmp(rsp, "PIN") == 0) {
171
 
                os_free(ssid->pin);
172
 
                ssid->pin = os_strdup(pos);
 
189
        } else if (strcmp(rsp, "PIN") == 0) {
 
190
                free(ssid->pin);
 
191
                ssid->pin = strdup(pos);
173
192
                ssid->pending_req_pin = 0;
174
193
                if (ssid == wpa_s->current_ssid)
175
194
                        wpa_s->reassociate = 1;
176
 
        } else if (os_strcmp(rsp, "OTP") == 0) {
177
 
                os_free(ssid->otp);
178
 
                ssid->otp = (u8 *) os_strdup(pos);
179
 
                ssid->otp_len = os_strlen(pos);
180
 
                os_free(ssid->pending_req_otp);
 
195
        } else if (strcmp(rsp, "OTP") == 0) {
 
196
                free(ssid->otp);
 
197
                ssid->otp = (u8 *) strdup(pos);
 
198
                ssid->otp_len = strlen(pos);
 
199
                free(ssid->pending_req_otp);
181
200
                ssid->pending_req_otp = NULL;
182
201
                ssid->pending_req_otp_len = 0;
183
 
        } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
184
 
                os_free(ssid->private_key_passwd);
185
 
                ssid->private_key_passwd = (u8 *) os_strdup(pos);
 
202
        } else if (strcmp(rsp, "PASSPHRASE") == 0) {
 
203
                free(ssid->private_key_passwd);
 
204
                ssid->private_key_passwd = (u8 *) strdup(pos);
186
205
                ssid->pending_req_passphrase = 0;
187
206
                if (ssid == wpa_s->current_ssid)
188
207
                        wpa_s->reassociate = 1;
206
225
        char *pos, *end, tmp[30];
207
226
        int res, verbose, ret;
208
227
 
209
 
        verbose = os_strcmp(params, "-VERBOSE") == 0;
 
228
        verbose = strcmp(params, "-VERBOSE") == 0;
210
229
        pos = buf;
211
230
        end = buf + buflen;
212
231
        if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
213
232
                struct wpa_ssid *ssid = wpa_s->current_ssid;
214
 
                ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
215
 
                                  MAC2STR(wpa_s->bssid));
 
233
                ret = snprintf(pos, end - pos, "bssid=" MACSTR "\n",
 
234
                               MAC2STR(wpa_s->bssid));
216
235
                if (ret < 0 || ret >= end - pos)
217
236
                        return pos - buf;
218
237
                pos += ret;
221
240
                        size_t ssid_len = ssid->ssid_len;
222
241
                        u8 ssid_buf[MAX_SSID_LEN];
223
242
                        if (ssid_len == 0) {
224
 
                                int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
225
 
                                if (_res < 0)
 
243
                                int res = wpa_drv_get_ssid(wpa_s, ssid_buf);
 
244
                                if (res < 0)
226
245
                                        ssid_len = 0;
227
246
                                else
228
 
                                        ssid_len = _res;
 
247
                                        ssid_len = res;
229
248
                                _ssid = ssid_buf;
230
249
                        }
231
 
                        ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
232
 
                                          wpa_ssid_txt(_ssid, ssid_len),
233
 
                                          ssid->id);
 
250
                        ret = snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
 
251
                                       wpa_ssid_txt(_ssid, ssid_len),
 
252
                                       ssid->id);
234
253
                        if (ret < 0 || ret >= end - pos)
235
254
                                return pos - buf;
236
255
                        pos += ret;
237
256
 
238
257
                        if (ssid->id_str) {
239
 
                                ret = os_snprintf(pos, end - pos,
240
 
                                                  "id_str=%s\n",
241
 
                                                  ssid->id_str);
 
258
                                ret = snprintf(pos, end - pos, "id_str=%s\n",
 
259
                                               ssid->id_str);
242
260
                                if (ret < 0 || ret >= end - pos)
243
261
                                        return pos - buf;
244
262
                                pos += ret;
247
265
 
248
266
                pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
249
267
        }
250
 
        ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
251
 
                          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));
252
270
        if (ret < 0 || ret >= end - pos)
253
271
                return pos - buf;
254
272
        pos += ret;
255
273
 
256
274
        if (wpa_s->l2 &&
257
275
            l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
258
 
                ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
 
276
                ret = snprintf(pos, end - pos, "ip_address=%s\n", tmp);
259
277
                if (ret < 0 || ret >= end - pos)
260
278
                        return pos - buf;
261
279
                pos += ret;
286
304
        u8 bssid[ETH_ALEN];
287
305
 
288
306
        /* cmd: "<network id> <BSSID>" */
289
 
        pos = os_strchr(cmd, ' ');
 
307
        pos = strchr(cmd, ' ');
290
308
        if (pos == NULL)
291
309
                return -1;
292
310
        *pos++ = '\0';
304
322
                return -1;
305
323
        }
306
324
 
307
 
        os_memcpy(ssid->bssid, bssid, ETH_ALEN);
 
325
        memcpy(ssid->bssid, bssid, ETH_ALEN);
308
326
        ssid->bssid_set =
309
 
                os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
 
327
                memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
310
328
                
311
329
 
312
330
        return 0;
322
340
 
323
341
        pos = buf;
324
342
        end = buf + buflen;
325
 
        ret = os_snprintf(pos, end - pos,
326
 
                          "network id / ssid / bssid / flags\n");
 
343
        ret = snprintf(pos, end - pos, "network id / ssid / bssid / flags\n");
327
344
        if (ret < 0 || ret >= end - pos)
328
345
                return pos - buf;
329
346
        pos += ret;
330
347
 
331
348
        ssid = wpa_s->conf->ssid;
332
349
        while (ssid) {
333
 
                ret = os_snprintf(pos, end - pos, "%d\t%s",
334
 
                                  ssid->id,
335
 
                                  wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
 
350
                ret = snprintf(pos, end - pos, "%d\t%s",
 
351
                               ssid->id,
 
352
                               wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
336
353
                if (ret < 0 || ret >= end - pos)
337
354
                        return pos - buf;
338
355
                pos += ret;
339
356
                if (ssid->bssid_set) {
340
 
                        ret = os_snprintf(pos, end - pos, "\t" MACSTR,
341
 
                                          MAC2STR(ssid->bssid));
 
357
                        ret = snprintf(pos, end - pos, "\t" MACSTR,
 
358
                                       MAC2STR(ssid->bssid));
342
359
                } else {
343
 
                        ret = os_snprintf(pos, end - pos, "\tany");
 
360
                        ret = snprintf(pos, end - pos, "\tany");
344
361
                }
345
362
                if (ret < 0 || ret >= end - pos)
346
363
                        return pos - buf;
347
364
                pos += ret;
348
 
                ret = os_snprintf(pos, end - pos, "\t%s%s",
349
 
                                  ssid == wpa_s->current_ssid ?
350
 
                                  "[CURRENT]" : "",
351
 
                                  ssid->disabled ? "[DISABLED]" : "");
 
365
                ret = snprintf(pos, end - pos, "\t%s%s",
 
366
                               ssid == wpa_s->current_ssid ? "[CURRENT]" : "",
 
367
                               ssid->disabled ? "[DISABLED]" : "");
352
368
                if (ret < 0 || ret >= end - pos)
353
369
                        return pos - buf;
354
370
                pos += ret;
355
 
                ret = os_snprintf(pos, end - pos, "\n");
 
371
                ret = snprintf(pos, end - pos, "\n");
356
372
                if (ret < 0 || ret >= end - pos)
357
373
                        return pos - buf;
358
374
                pos += ret;
367
383
static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
368
384
{
369
385
        int first = 1, ret;
370
 
        ret = os_snprintf(pos, end - pos, "-");
 
386
        ret = snprintf(pos, end - pos, "-");
371
387
        if (ret < 0 || ret >= end - pos)
372
388
                return pos;
373
389
        pos += ret;
374
390
        if (cipher & WPA_CIPHER_NONE) {
375
 
                ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
 
391
                ret = snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
376
392
                if (ret < 0 || ret >= end - pos)
377
393
                        return pos;
378
394
                pos += ret;
379
395
                first = 0;
380
396
        }
381
397
        if (cipher & WPA_CIPHER_WEP40) {
382
 
                ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
 
398
                ret = snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
383
399
                if (ret < 0 || ret >= end - pos)
384
400
                        return pos;
385
401
                pos += ret;
386
402
                first = 0;
387
403
        }
388
404
        if (cipher & WPA_CIPHER_WEP104) {
389
 
                ret = os_snprintf(pos, end - pos, "%sWEP104",
390
 
                                  first ? "" : "+");
 
405
                ret = snprintf(pos, end - pos, "%sWEP104", first ? "" : "+");
391
406
                if (ret < 0 || ret >= end - pos)
392
407
                        return pos;
393
408
                pos += ret;
394
409
                first = 0;
395
410
        }
396
411
        if (cipher & WPA_CIPHER_TKIP) {
397
 
                ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
 
412
                ret = snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
398
413
                if (ret < 0 || ret >= end - pos)
399
414
                        return pos;
400
415
                pos += ret;
401
416
                first = 0;
402
417
        }
403
418
        if (cipher & WPA_CIPHER_CCMP) {
404
 
                ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
 
419
                ret = snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
405
420
                if (ret < 0 || ret >= end - pos)
406
421
                        return pos;
407
422
                pos += ret;
417
432
        struct wpa_ie_data data;
418
433
        int first, ret;
419
434
 
420
 
        ret = os_snprintf(pos, end - pos, "[%s-", proto);
 
435
        ret = snprintf(pos, end - pos, "[%s-", proto);
421
436
        if (ret < 0 || ret >= end - pos)
422
437
                return pos;
423
438
        pos += ret;
424
439
 
425
440
        if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
426
 
                ret = os_snprintf(pos, end - pos, "?]");
 
441
                ret = snprintf(pos, end - pos, "?]");
427
442
                if (ret < 0 || ret >= end - pos)
428
443
                        return pos;
429
444
                pos += ret;
432
447
 
433
448
        first = 1;
434
449
        if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
435
 
                ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
 
450
                ret = snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
436
451
                if (ret < 0 || ret >= end - pos)
437
452
                        return pos;
438
453
                pos += ret;
439
454
                first = 0;
440
455
        }
441
456
        if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
442
 
                ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
 
457
                ret = snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
443
458
                if (ret < 0 || ret >= end - pos)
444
459
                        return pos;
445
460
                pos += ret;
446
461
                first = 0;
447
462
        }
448
463
        if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
449
 
                ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
 
464
                ret = snprintf(pos, end - pos, "%sNone", first ? "" : "+");
450
465
                if (ret < 0 || ret >= end - pos)
451
466
                        return pos;
452
467
                pos += ret;
456
471
        pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
457
472
 
458
473
        if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
459
 
                ret = os_snprintf(pos, end - pos, "-preauth");
 
474
                ret = snprintf(pos, end - pos, "-preauth");
460
475
                if (ret < 0 || ret >= end - pos)
461
476
                        return pos;
462
477
                pos += ret;
463
478
        }
464
479
 
465
 
        ret = os_snprintf(pos, end - pos, "]");
 
480
        ret = snprintf(pos, end - pos, "]");
466
481
        if (ret < 0 || ret >= end - pos)
467
482
                return pos;
468
483
        pos += ret;
481
496
        if (wpa_s->scan_results == NULL &&
482
497
            wpa_supplicant_get_scan_results(wpa_s) < 0)
483
498
                return 0;
484
 
        if (wpa_s->scan_results == NULL)
485
 
                return 0;
486
499
 
487
500
        pos = buf;
488
501
        end = buf + buflen;
489
 
        ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
490
 
                          "flags / ssid\n");
 
502
        ret = snprintf(pos, end - pos, "bssid / frequency / signal level / "
 
503
                       "flags / ssid\n");
491
504
        if (ret < 0 || ret >= end - pos)
492
505
                return pos - buf;
493
506
        pos += ret;
494
507
 
495
508
        for (i = 0; i < wpa_s->num_scan_results; i++) {
496
509
                res = &wpa_s->scan_results[i];
497
 
                ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
498
 
                                  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);
499
512
                if (ret < 0 || ret >= end - pos)
500
513
                        return pos - buf;
501
514
                pos += ret;
511
524
                }
512
525
                if (!res->wpa_ie_len && !res->rsn_ie_len &&
513
526
                    res->caps & IEEE80211_CAP_PRIVACY) {
514
 
                        ret = os_snprintf(pos, end - pos, "[WEP]");
 
527
                        ret = snprintf(pos, end - pos, "[WEP]");
515
528
                        if (ret < 0 || ret >= end - pos)
516
529
                                return pos - buf;
517
530
                        pos += ret;
518
531
                }
519
532
                if (res->caps & IEEE80211_CAP_IBSS) {
520
 
                        ret = os_snprintf(pos, end - pos, "[IBSS]");
 
533
                        ret = snprintf(pos, end - pos, "[IBSS]");
521
534
                        if (ret < 0 || ret >= end - pos)
522
535
                                return pos - buf;
523
536
                        pos += ret;
524
537
                }
525
538
 
526
 
                ret = os_snprintf(pos, end - pos, "\t%s",
527
 
                                  wpa_ssid_txt(res->ssid, res->ssid_len));
 
539
                ret = snprintf(pos, end - pos, "\t%s",
 
540
                               wpa_ssid_txt(res->ssid, res->ssid_len));
528
541
                if (ret < 0 || ret >= end - pos)
529
542
                        return pos - buf;
530
543
                pos += ret;
531
544
 
532
 
                ret = os_snprintf(pos, end - pos, "\n");
 
545
                ret = snprintf(pos, end - pos, "\n");
533
546
                if (ret < 0 || ret >= end - pos)
534
547
                        return pos - buf;
535
548
                pos += ret;
546
559
        struct wpa_ssid *ssid;
547
560
 
548
561
        /* cmd: "<network id>" or "any" */
549
 
        if (os_strcmp(cmd, "any") == 0) {
 
562
        if (strcmp(cmd, "any") == 0) {
550
563
                wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
551
564
                ssid = wpa_s->conf->ssid;
552
565
                while (ssid) {
653
666
        ssid->disabled = 1;
654
667
        wpa_config_set_network_defaults(ssid);
655
668
 
656
 
        ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
 
669
        ret = snprintf(buf, buflen, "%d\n", ssid->id);
657
670
        if (ret < 0 || (size_t) ret >= buflen)
658
671
                return -1;
659
672
        return ret;
678
691
                return -1;
679
692
        }
680
693
 
681
 
        if (ssid == wpa_s->current_ssid) {
682
 
                /*
683
 
                 * Invalidate the EAP session cache if the current network is
684
 
                 * removed.
685
 
                 */
686
 
                eapol_sm_invalidate_cached_session(wpa_s->eapol);
687
 
 
 
694
        if (ssid == wpa_s->current_ssid)
688
695
                wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
689
 
        }
690
696
 
691
697
        return 0;
692
698
}
700
706
        char *name, *value;
701
707
 
702
708
        /* cmd: "<network id> <variable name> <value>" */
703
 
        name = os_strchr(cmd, ' ');
 
709
        name = strchr(cmd, ' ');
704
710
        if (name == NULL)
705
711
                return -1;
706
712
        *name++ = '\0';
707
713
 
708
 
        value = os_strchr(name, ' ');
 
714
        value = strchr(name, ' ');
709
715
        if (value == NULL)
710
716
                return -1;
711
717
        *value++ = '\0';
714
720
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
715
721
                   id, name);
716
722
        wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
717
 
                              (u8 *) value, os_strlen(value));
 
723
                              (u8 *) value, strlen(value));
718
724
 
719
725
        ssid = wpa_config_get_network(wpa_s->conf, id);
720
726
        if (ssid == NULL) {
729
735
                return -1;
730
736
        }
731
737
 
732
 
        if (wpa_s->current_ssid == ssid) {
733
 
                /*
734
 
                 * Invalidate the EAP session cache if anything in the current
735
 
                 * configuration changes.
736
 
                 */
737
 
                eapol_sm_invalidate_cached_session(wpa_s->eapol);
738
 
        }
739
 
 
740
 
        if ((os_strcmp(name, "psk") == 0 &&
741
 
             value[0] == '"' && ssid->ssid_len) ||
742
 
            (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
 
738
        if ((strcmp(name, "psk") == 0 && value[0] == '"' && ssid->ssid_len) ||
 
739
            (strcmp(name, "ssid") == 0 && ssid->passphrase))
743
740
                wpa_config_update_psk(ssid);
744
741
 
745
742
        return 0;
754
751
        char *name, *value;
755
752
 
756
753
        /* cmd: "<network id> <variable name>" */
757
 
        name = os_strchr(cmd, ' ');
 
754
        name = strchr(cmd, ' ');
758
755
        if (name == NULL || buflen == 0)
759
756
                return -1;
760
757
        *name++ = '\0';
770
767
                return -1;
771
768
        }
772
769
 
773
 
        value = wpa_config_get_no_key(ssid, name);
 
770
        value = wpa_config_get(ssid, name);
774
771
        if (value == NULL) {
775
772
                wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
776
773
                           "variable '%s'", name);
777
774
                return -1;
778
775
        }
779
776
 
780
 
        os_snprintf(buf, buflen, "%s", value);
 
777
        snprintf(buf, buflen, "%s", value);
781
778
        buf[buflen - 1] = '\0';
782
779
 
783
 
        os_free(value);
 
780
        free(value);
784
781
 
785
 
        return os_strlen(buf);
 
782
        return strlen(buf);
786
783
}
787
784
 
788
785
 
819
816
        char field[30];
820
817
 
821
818
        /* Determine whether or not strict checking was requested */
822
 
        os_snprintf(field, sizeof(field), "%s", _field);
 
819
        snprintf(field, sizeof(field), "%s", _field);
823
820
        field[sizeof(field) - 1] = '\0';
824
 
        strict = os_strchr(field, ' ');
 
821
        strict = strchr(field, ' ');
825
822
        if (strict != NULL) {
826
823
                *strict++ = '\0';
827
 
                if (os_strcmp(strict, "strict") != 0)
 
824
                if (strcmp(strict, "strict") != 0) {
 
825
                        free(field);
828
826
                        return -1;
 
827
                }
829
828
        }
830
829
 
831
830
        wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
832
831
                field, strict ? strict : "");
833
832
 
834
 
        if (os_strcmp(field, "eap") == 0) {
 
833
        if (strcmp(field, "eap") == 0) {
835
834
                return eap_get_names(buf, buflen);
836
835
        }
837
836
 
840
839
        pos = buf;
841
840
        end = pos + buflen;
842
841
 
843
 
        if (os_strcmp(field, "pairwise") == 0) {
 
842
        if (strcmp(field, "pairwise") == 0) {
844
843
                if (res < 0) {
845
844
                        if (strict)
846
845
                                return 0;
847
 
                        ret = os_snprintf(buf, buflen, "CCMP TKIP NONE");
 
846
                        ret = snprintf(buf, buflen, "CCMP TKIP NONE");
848
847
                        if (ret < 0 || (size_t) ret >= buflen)
849
848
                                return -1;
850
849
                        return ret;
851
850
                }
852
851
 
853
852
                if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
854
 
                        ret = os_snprintf(pos, end - pos, "%sCCMP",
855
 
                                          first ? "" : " ");
 
853
                        ret = snprintf(pos, end - pos, "%sCCMP",
 
854
                                       first ? "" : " ");
856
855
                        if (ret < 0 || ret >= end - pos)
857
856
                                return pos - buf;
858
857
                        pos += ret;
860
859
                }
861
860
 
862
861
                if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
863
 
                        ret = os_snprintf(pos, end - pos, "%sTKIP",
864
 
                                          first ? "" : " ");
 
862
                        ret = snprintf(pos, end - pos, "%sTKIP",
 
863
                                       first ? "" : " ");
865
864
                        if (ret < 0 || ret >= end - pos)
866
865
                                return pos - buf;
867
866
                        pos += ret;
869
868
                }
870
869
 
871
870
                if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
872
 
                        ret = os_snprintf(pos, end - pos, "%sNONE",
873
 
                                          first ? "" : " ");
 
871
                        ret = snprintf(pos, end - pos, "%sNONE",
 
872
                                       first ? "" : " ");
874
873
                        if (ret < 0 || ret >= end - pos)
875
874
                                return pos - buf;
876
875
                        pos += ret;
880
879
                return pos - buf;
881
880
        }
882
881
 
883
 
        if (os_strcmp(field, "group") == 0) {
 
882
        if (strcmp(field, "group") == 0) {
884
883
                if (res < 0) {
885
884
                        if (strict)
886
885
                                return 0;
887
 
                        ret = os_snprintf(buf, buflen,
888
 
                                          "CCMP TKIP WEP104 WEP40");
 
886
                        ret = snprintf(buf, buflen, "CCMP TKIP WEP104 WEP40");
889
887
                        if (ret < 0 || (size_t) ret >= buflen)
890
888
                                return -1;
891
889
                        return ret;
892
890
                }
893
891
 
894
892
                if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
895
 
                        ret = os_snprintf(pos, end - pos, "%sCCMP",
896
 
                                          first ? "" : " ");
 
893
                        ret = snprintf(pos, end - pos, "%sCCMP",
 
894
                                       first ? "" : " ");
897
895
                        if (ret < 0 || ret >= end - pos)
898
896
                                return pos - buf;
899
897
                        pos += ret;
901
899
                }
902
900
 
903
901
                if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
904
 
                        ret = os_snprintf(pos, end - pos, "%sTKIP",
905
 
                                          first ? "" : " ");
 
902
                        ret = snprintf(pos, end - pos, "%sTKIP",
 
903
                                       first ? "" : " ");
906
904
                        if (ret < 0 || ret >= end - pos)
907
905
                                return pos - buf;
908
906
                        pos += ret;
910
908
                }
911
909
 
912
910
                if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
913
 
                        ret = os_snprintf(pos, end - pos, "%sWEP104",
914
 
                                          first ? "" : " ");
 
911
                        ret = snprintf(pos, end - pos, "%sWEP104",
 
912
                                       first ? "" : " ");
915
913
                        if (ret < 0 || ret >= end - pos)
916
914
                                return pos - buf;
917
915
                        pos += ret;
919
917
                }
920
918
 
921
919
                if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
922
 
                        ret = os_snprintf(pos, end - pos, "%sWEP40",
923
 
                                          first ? "" : " ");
 
920
                        ret = snprintf(pos, end - pos, "%sWEP40",
 
921
                                       first ? "" : " ");
924
922
                        if (ret < 0 || ret >= end - pos)
925
923
                                return pos - buf;
926
924
                        pos += ret;
930
928
                return pos - buf;
931
929
        }
932
930
 
933
 
        if (os_strcmp(field, "key_mgmt") == 0) {
 
931
        if (strcmp(field, "key_mgmt") == 0) {
934
932
                if (res < 0) {
935
933
                        if (strict)
936
934
                                return 0;
937
 
                        ret = os_snprintf(buf, buflen, "WPA-PSK WPA-EAP "
938
 
                                          "IEEE8021X WPA-NONE NONE");
 
935
                        ret = snprintf(buf, buflen, "WPA-PSK WPA-EAP "
 
936
                                       "IEEE8021X WPA-NONE NONE");
939
937
                        if (ret < 0 || (size_t) ret >= buflen)
940
938
                                return -1;
941
939
                        return ret;
942
940
                }
943
941
 
944
 
                ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
 
942
                ret = snprintf(pos, end - pos, "NONE IEEE8021X");
945
943
                if (ret < 0 || ret >= end - pos)
946
944
                        return pos - buf;
947
945
                pos += ret;
948
946
 
949
947
                if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
950
948
                                     WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
951
 
                        ret = os_snprintf(pos, end - pos, " WPA-EAP");
 
949
                        ret = snprintf(pos, end - pos, " WPA-EAP");
952
950
                        if (ret < 0 || ret >= end - pos)
953
951
                                return pos - buf;
954
952
                        pos += ret;
956
954
 
957
955
                if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
958
956
                                     WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
959
 
                        ret = os_snprintf(pos, end - pos, " WPA-PSK");
 
957
                        ret = snprintf(pos, end - pos, " WPA-PSK");
960
958
                        if (ret < 0 || ret >= end - pos)
961
959
                                return pos - buf;
962
960
                        pos += ret;
963
961
                }
964
962
 
965
963
                if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
966
 
                        ret = os_snprintf(pos, end - pos, " WPA-NONE");
 
964
                        ret = snprintf(pos, end - pos, " WPA-NONE");
967
965
                        if (ret < 0 || ret >= end - pos)
968
966
                                return pos - buf;
969
967
                        pos += ret;
972
970
                return pos - buf;
973
971
        }
974
972
 
975
 
        if (os_strcmp(field, "proto") == 0) {
 
973
        if (strcmp(field, "proto") == 0) {
976
974
                if (res < 0) {
977
975
                        if (strict)
978
976
                                return 0;
979
 
                        ret = os_snprintf(buf, buflen, "RSN WPA");
 
977
                        ret = snprintf(buf, buflen, "RSN WPA");
980
978
                        if (ret < 0 || (size_t) ret >= buflen)
981
979
                                return -1;
982
980
                        return ret;
984
982
 
985
983
                if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
986
984
                                     WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
987
 
                        ret = os_snprintf(pos, end - pos, "%sRSN",
988
 
                                          first ? "" : " ");
 
985
                        ret = snprintf(pos, end - pos, "%sRSN",
 
986
                                       first ? "" : " ");
989
987
                        if (ret < 0 || ret >= end - pos)
990
988
                                return pos - buf;
991
989
                        pos += ret;
994
992
 
995
993
                if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
996
994
                                     WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
997
 
                        ret = os_snprintf(pos, end - pos, "%sWPA",
998
 
                                          first ? "" : " ");
 
995
                        ret = snprintf(pos, end - pos, "%sWPA",
 
996
                                       first ? "" : " ");
999
997
                        if (ret < 0 || ret >= end - pos)
1000
998
                                return pos - buf;
1001
999
                        pos += ret;
1005
1003
                return pos - buf;
1006
1004
        }
1007
1005
 
1008
 
        if (os_strcmp(field, "auth_alg") == 0) {
 
1006
        if (strcmp(field, "auth_alg") == 0) {
1009
1007
                if (res < 0) {
1010
1008
                        if (strict)
1011
1009
                                return 0;
1012
 
                        ret = os_snprintf(buf, buflen, "OPEN SHARED LEAP");
 
1010
                        ret = snprintf(buf, buflen, "OPEN SHARED LEAP");
1013
1011
                        if (ret < 0 || (size_t) ret >= buflen)
1014
1012
                                return -1;
1015
1013
                        return ret;
1016
1014
                }
1017
1015
 
1018
1016
                if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
1019
 
                        ret = os_snprintf(pos, end - pos, "%sOPEN",
1020
 
                                          first ? "" : " ");
 
1017
                        ret = snprintf(pos, end - pos, "%sOPEN",
 
1018
                                       first ? "" : " ");
1021
1019
                        if (ret < 0 || ret >= end - pos)
1022
1020
                                return pos - buf;
1023
1021
                        pos += ret;
1025
1023
                }
1026
1024
 
1027
1025
                if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
1028
 
                        ret = os_snprintf(pos, end - pos, "%sSHARED",
1029
 
                                          first ? "" : " ");
 
1026
                        ret = snprintf(pos, end - pos, "%sSHARED",
 
1027
                                       first ? "" : " ");
1030
1028
                        if (ret < 0 || ret >= end - pos)
1031
1029
                                return pos - buf;
1032
1030
                        pos += ret;
1034
1032
                }
1035
1033
 
1036
1034
                if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
1037
 
                        ret = os_snprintf(pos, end - pos, "%sLEAP",
1038
 
                                          first ? "" : " ");
 
1035
                        ret = snprintf(pos, end - pos, "%sLEAP",
 
1036
                                       first ? "" : " ");
1039
1037
                        if (ret < 0 || ret >= end - pos)
1040
1038
                                return pos - buf;
1041
1039
                        pos += ret;
1072
1070
        int ctrl_rsp = 0;
1073
1071
        int reply_len;
1074
1072
 
1075
 
        if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
1076
 
            os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
 
1073
        if (strncmp(buf, WPA_CTRL_RSP, strlen(WPA_CTRL_RSP)) == 0 ||
 
1074
            strncmp(buf, "SET_NETWORK ", 12) == 0) {
1077
1075
                wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
1078
 
                                      (const u8 *) buf, os_strlen(buf));
 
1076
                                      (const u8 *) buf, strlen(buf));
1079
1077
        } else {
1080
1078
                wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface",
1081
 
                                  (const u8 *) buf, os_strlen(buf));
 
1079
                                  (const u8 *) buf, strlen(buf));
1082
1080
        }
1083
1081
 
1084
 
        reply = os_malloc(reply_size);
 
1082
        reply = malloc(reply_size);
1085
1083
        if (reply == NULL) {
1086
1084
                *resp_len = 1;
1087
1085
                return NULL;
1088
1086
        }
1089
1087
 
1090
 
        os_memcpy(reply, "OK\n", 3);
 
1088
        memcpy(reply, "OK\n", 3);
1091
1089
        reply_len = 3;
1092
1090
 
1093
 
        if (os_strcmp(buf, "PING") == 0) {
1094
 
                os_memcpy(reply, "PONG\n", 5);
 
1091
        if (strcmp(buf, "PING") == 0) {
 
1092
                memcpy(reply, "PONG\n", 5);
1095
1093
                reply_len = 5;
1096
 
        } else if (os_strcmp(buf, "MIB") == 0) {
 
1094
        } else if (strcmp(buf, "MIB") == 0) {
1097
1095
                reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
1098
1096
                if (reply_len >= 0) {
1099
1097
                        int res;
1104
1102
                        else
1105
1103
                                reply_len += res;
1106
1104
                }
1107
 
        } else if (os_strncmp(buf, "STATUS", 6) == 0) {
 
1105
        } else if (strncmp(buf, "STATUS", 6) == 0) {
1108
1106
                reply_len = wpa_supplicant_ctrl_iface_status(
1109
1107
                        wpa_s, buf + 6, reply, reply_size);
1110
 
        } else if (os_strcmp(buf, "PMKSA") == 0) {
 
1108
        } else if (strcmp(buf, "PMKSA") == 0) {
1111
1109
                reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
1112
 
        } else if (os_strncmp(buf, "SET ", 4) == 0) {
 
1110
        } else if (strncmp(buf, "SET ", 4) == 0) {
1113
1111
                if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
1114
1112
                        reply_len = -1;
1115
 
        } else if (os_strcmp(buf, "LOGON") == 0) {
 
1113
        } else if (strcmp(buf, "LOGON") == 0) {
1116
1114
                eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
1117
 
        } else if (os_strcmp(buf, "LOGOFF") == 0) {
 
1115
        } else if (strcmp(buf, "LOGOFF") == 0) {
1118
1116
                eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
1119
 
        } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
 
1117
        } else if (strcmp(buf, "REASSOCIATE") == 0) {
1120
1118
                wpa_s->disconnected = 0;
1121
1119
                wpa_s->reassociate = 1;
1122
1120
                wpa_supplicant_req_scan(wpa_s, 0, 0);
1123
 
        } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
 
1121
        } else if (strncmp(buf, "PREAUTH ", 8) == 0) {
1124
1122
                if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
1125
1123
                        reply_len = -1;
 
1124
#ifdef CONFIG_STAKEY
 
1125
        } else if (strncmp(buf, "STAKEY-REQUEST ", 15) == 0) {
 
1126
                if (wpa_supplicant_ctrl_iface_stakey_request(wpa_s, buf + 15))
 
1127
                        reply_len = -1;
 
1128
#endif /* CONFIG_STAKEY */
1126
1129
#ifdef CONFIG_PEERKEY
1127
 
        } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
 
1130
        } else if (strncmp(buf, "STKSTART ", 9) == 0) {
1128
1131
                if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
1129
1132
                        reply_len = -1;
1130
1133
#endif /* CONFIG_PEERKEY */
1131
 
        } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
1132
 
        {
 
1134
        } else if (strncmp(buf, WPA_CTRL_RSP, strlen(WPA_CTRL_RSP)) == 0) {
1133
1135
                if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1134
 
                            wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
 
1136
                            wpa_s, buf + strlen(WPA_CTRL_RSP)))
1135
1137
                        reply_len = -1;
1136
1138
                else
1137
1139
                        ctrl_rsp = 1;
1138
 
        } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
 
1140
        } else if (strcmp(buf, "RECONFIGURE") == 0) {
1139
1141
                if (wpa_supplicant_reload_configuration(wpa_s))
1140
1142
                        reply_len = -1;
1141
 
        } else if (os_strcmp(buf, "TERMINATE") == 0) {
 
1143
        } else if (strcmp(buf, "TERMINATE") == 0) {
1142
1144
                eloop_terminate();
1143
 
        } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
 
1145
        } else if (strncmp(buf, "BSSID ", 6) == 0) {
1144
1146
                if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
1145
1147
                        reply_len = -1;
1146
 
        } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
 
1148
        } else if (strcmp(buf, "LIST_NETWORKS") == 0) {
1147
1149
                reply_len = wpa_supplicant_ctrl_iface_list_networks(
1148
1150
                        wpa_s, reply, reply_size);
1149
 
        } else if (os_strcmp(buf, "DISCONNECT") == 0) {
 
1151
        } else if (strcmp(buf, "DISCONNECT") == 0) {
1150
1152
                wpa_s->disconnected = 1;
1151
1153
                wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
1152
 
        } else if (os_strcmp(buf, "SCAN") == 0) {
 
1154
        } else if (strcmp(buf, "SCAN") == 0) {
1153
1155
                wpa_s->scan_req = 2;
1154
1156
                wpa_supplicant_req_scan(wpa_s, 0, 0);
1155
 
        } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
 
1157
        } else if (strcmp(buf, "SCAN_RESULTS") == 0) {
1156
1158
                reply_len = wpa_supplicant_ctrl_iface_scan_results(
1157
1159
                        wpa_s, reply, reply_size);
1158
 
        } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
 
1160
        } else if (strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
1159
1161
                if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
1160
1162
                        reply_len = -1;
1161
 
        } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
 
1163
        } else if (strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
1162
1164
                if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
1163
1165
                        reply_len = -1;
1164
 
        } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
 
1166
        } else if (strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
1165
1167
                if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
1166
1168
                        reply_len = -1;
1167
 
        } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
 
1169
        } else if (strcmp(buf, "ADD_NETWORK") == 0) {
1168
1170
                reply_len = wpa_supplicant_ctrl_iface_add_network(
1169
1171
                        wpa_s, reply, reply_size);
1170
 
        } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
 
1172
        } else if (strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
1171
1173
                if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
1172
1174
                        reply_len = -1;
1173
 
        } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
 
1175
        } else if (strncmp(buf, "SET_NETWORK ", 12) == 0) {
1174
1176
                if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
1175
1177
                        reply_len = -1;
1176
 
        } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
 
1178
        } else if (strncmp(buf, "GET_NETWORK ", 12) == 0) {
1177
1179
                reply_len = wpa_supplicant_ctrl_iface_get_network(
1178
1180
                        wpa_s, buf + 12, reply, reply_size);
1179
 
        } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
 
1181
        } else if (strcmp(buf, "SAVE_CONFIG") == 0) {
1180
1182
                if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
1181
1183
                        reply_len = -1;
1182
 
        } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
 
1184
        } else if (strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
1183
1185
                reply_len = wpa_supplicant_ctrl_iface_get_capability(
1184
1186
                        wpa_s, buf + 15, reply, reply_size);
1185
 
        } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
 
1187
        } else if (strncmp(buf, "AP_SCAN ", 8) == 0) {
1186
1188
                if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
1187
1189
                        reply_len = -1;
1188
 
        } else if (os_strcmp(buf, "INTERFACES") == 0) {
 
1190
        } else if (strcmp(buf, "INTERFACES") == 0) {
1189
1191
                reply_len = wpa_supplicant_global_iface_interfaces(
1190
1192
                        wpa_s->global, reply, reply_size);
1191
1193
        } else {
1192
 
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
 
1194
                memcpy(reply, "UNKNOWN COMMAND\n", 16);
1193
1195
                reply_len = 16;
1194
1196
        }
1195
1197
 
1196
1198
        if (reply_len < 0) {
1197
 
                os_memcpy(reply, "FAIL\n", 5);
 
1199
                memcpy(reply, "FAIL\n", 5);
1198
1200
                reply_len = 5;
1199
1201
        }
1200
1202
 
1218
1220
         */
1219
1221
        wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
1220
1222
 
1221
 
        os_memset(&iface, 0, sizeof(iface));
 
1223
        memset(&iface, 0, sizeof(iface));
1222
1224
 
1223
1225
        do {
1224
1226
                iface.ifname = pos = cmd;
1225
 
                pos = os_strchr(pos, '\t');
 
1227
                pos = strchr(pos, '\t');
1226
1228
                if (pos)
1227
1229
                        *pos++ = '\0';
1228
1230
                if (iface.ifname[0] == '\0')
1231
1233
                        break;
1232
1234
 
1233
1235
                iface.confname = pos;
1234
 
                pos = os_strchr(pos, '\t');
 
1236
                pos = strchr(pos, '\t');
1235
1237
                if (pos)
1236
1238
                        *pos++ = '\0';
1237
1239
                if (iface.confname[0] == '\0')
1240
1242
                        break;
1241
1243
 
1242
1244
                iface.driver = pos;
1243
 
                pos = os_strchr(pos, '\t');
 
1245
                pos = strchr(pos, '\t');
1244
1246
                if (pos)
1245
1247
                        *pos++ = '\0';
1246
1248
                if (iface.driver[0] == '\0')
1249
1251
                        break;
1250
1252
 
1251
1253
                iface.ctrl_interface = pos;
1252
 
                pos = os_strchr(pos, '\t');
 
1254
                pos = strchr(pos, '\t');
1253
1255
                if (pos)
1254
1256
                        *pos++ = '\0';
1255
1257
                if (iface.ctrl_interface[0] == '\0')
1258
1260
                        break;
1259
1261
 
1260
1262
                iface.driver_param = pos;
1261
 
                pos = os_strchr(pos, '\t');
 
1263
                pos = strchr(pos, '\t');
1262
1264
                if (pos)
1263
1265
                        *pos++ = '\0';
1264
1266
                if (iface.driver_param[0] == '\0')
1267
1269
                        break;
1268
1270
 
1269
1271
                iface.bridge_ifname = pos;
1270
 
                pos = os_strchr(pos, '\t');
 
1272
                pos = strchr(pos, '\t');
1271
1273
                if (pos)
1272
1274
                        *pos++ = '\0';
1273
1275
                if (iface.bridge_ifname[0] == '\0')
1309
1311
        end = buf + len;
1310
1312
 
1311
1313
        while (wpa_s) {
1312
 
                res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
 
1314
                res = snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
1313
1315
                if (res < 0 || res >= end - pos) {
1314
1316
                        *pos = '\0';
1315
1317
                        break;
1329
1331
        int reply_len;
1330
1332
 
1331
1333
        wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
1332
 
                          (const u8 *) buf, os_strlen(buf));
 
1334
                          (const u8 *) buf, strlen(buf));
1333
1335
 
1334
 
        reply = os_malloc(reply_size);
 
1336
        reply = malloc(reply_size);
1335
1337
        if (reply == NULL) {
1336
1338
                *resp_len = 1;
1337
1339
                return NULL;
1338
1340
        }
1339
1341
 
1340
 
        os_memcpy(reply, "OK\n", 3);
 
1342
        memcpy(reply, "OK\n", 3);
1341
1343
        reply_len = 3;
1342
1344
 
1343
 
        if (os_strcmp(buf, "PING") == 0) {
1344
 
                os_memcpy(reply, "PONG\n", 5);
 
1345
        if (strcmp(buf, "PING") == 0) {
 
1346
                memcpy(reply, "PONG\n", 5);
1345
1347
                reply_len = 5;
1346
 
        } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
 
1348
        } else if (strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
1347
1349
                if (wpa_supplicant_global_iface_add(global, buf + 14))
1348
1350
                        reply_len = -1;
1349
 
        } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
 
1351
        } else if (strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
1350
1352
                if (wpa_supplicant_global_iface_remove(global, buf + 17))
1351
1353
                        reply_len = -1;
1352
 
        } else if (os_strcmp(buf, "INTERFACES") == 0) {
 
1354
        } else if (strcmp(buf, "INTERFACES") == 0) {
1353
1355
                reply_len = wpa_supplicant_global_iface_interfaces(
1354
1356
                        global, reply, reply_size);
1355
 
        } else if (os_strcmp(buf, "TERMINATE") == 0) {
1356
 
                eloop_terminate();
1357
1357
        } else {
1358
 
                os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
 
1358
                memcpy(reply, "UNKNOWN COMMAND\n", 16);
1359
1359
                reply_len = 16;
1360
1360
        }
1361
1361
 
1362
1362
        if (reply_len < 0) {
1363
 
                os_memcpy(reply, "FAIL\n", 5);
 
1363
                memcpy(reply, "FAIL\n", 5);
1364
1364
                reply_len = 5;
1365
1365
        }
1366
1366