--- wpa_ctrl.c 9 Sep 2006 16:31:45 -0000 1.22 +++ wpa_ctrl.c 12 Sep 2006 10:20:55 -0000 @@ -388,11 +388,28 @@ if (!WriteFile(ctrl->pipe, cmd, cmd_len, &written, NULL)) return -1; - if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL)) - return -1; - *reply_len = readlen; + for (;;) { + if (!ReadFile(ctrl->pipe, reply, *reply_len, &readlen, NULL)) + return -1; - return 0; + if (reply[0] == '<') { + /* This is an unsolicited message from + * wpa_supplicant, not the reply to the + * request. Use msg_cb to report this to the + * caller. */ + if (msg_cb) { + /* Make sure the message is nul + * terminated. */ + if ((size_t) readlen == *reply_len) + readlen = (*reply_len) - 1; + reply[readlen] = '\0'; + msg_cb(reply, readlen); + } + continue; + } + *reply_len = readlen; + return 0; + } }