WPS: Added event callback and M2D notification

The event callback will be used for various event messages and the M2D
notification is the first such message. It is used to notify wpa_gui
about Registrar not yet knowing the device password (PIN).
This commit is contained in:
Jouni Malinen 2008-12-18 21:58:42 +02:00
parent 9be0963605
commit 4b68290e77
5 changed files with 77 additions and 4 deletions

View File

@ -60,6 +60,8 @@ extern "C" {
#define WPS_EVENT_AP_AVAILABLE "WPS-AP-AVAILABLE "
/** A new credential received */
#define WPS_EVENT_CRED_RECEIVED "WPS-CRED-RECEIVED "
/** M2D received */
#define WPS_EVENT_M2D "WPS-M2D "
/* hostapd control interface - fixed message prefixes */
#define WPS_EVENT_PIN_NEEDED "WPS-PIN-NEEDED "

View File

@ -95,6 +95,29 @@ struct wps_registrar_config {
};
enum wps_event {
WPS_EV_M2D
};
union wps_event_data {
struct wps_event_m2d {
u16 config_methods;
const u8 *manufacturer;
size_t manufacturer_len;
const u8 *model_name;
size_t model_name_len;
const u8 *model_number;
size_t model_number_len;
const u8 *serial_number;
size_t serial_number_len;
const u8 *dev_name;
size_t dev_name_len;
const u8 *primary_dev_type; /* 8 octets */
u16 config_error;
u16 dev_password_id;
} m2d;
};
/**
* struct wps_context - Long term WPS context data
*
@ -117,6 +140,8 @@ struct wps_context {
size_t network_key_len;
int (*cred_cb)(void *ctx, const struct wps_credential *cred);
void (*event_cb)(void *ctx, enum wps_event event,
union wps_event_data *data);
void *cb_ctx;
};

View File

@ -733,10 +733,32 @@ static enum wps_process_res wps_process_m2d(struct wps_data *wps,
wpa_hexdump_ascii(MSG_DEBUG, "WPS: Device Name",
attr->dev_name, attr->dev_name_len);
/*
* TODO: notify monitor programs (cli/gui/etc.) of the M2D and provide
* user information about the registrar properties.
*/
if (wps->wps->event_cb) {
union wps_event_data data;
struct wps_event_m2d *m2d = &data.m2d;
os_memset(&data, 0, sizeof(data));
if (attr->config_methods)
m2d->config_methods =
WPA_GET_BE16(attr->config_methods);
m2d->manufacturer = attr->manufacturer;
m2d->manufacturer_len = attr->manufacturer_len;
m2d->model_name = attr->model_name;
m2d->model_name_len = attr->model_name_len;
m2d->model_number = attr->model_number;
m2d->model_number_len = attr->model_number_len;
m2d->serial_number = attr->serial_number;
m2d->serial_number_len = attr->serial_number_len;
m2d->dev_name = attr->dev_name;
m2d->dev_name_len = attr->dev_name_len;
m2d->primary_dev_type = attr->primary_dev_type;
if (attr->config_error)
m2d->config_error =
WPA_GET_BE16(attr->config_error);
if (attr->dev_password_id)
m2d->dev_password_id =
WPA_GET_BE16(attr->dev_password_id);
wps->wps->event_cb(wps->wps->cb_ctx, WPS_EV_M2D, &data);
}
wps->state = RECEIVED_M2D;
return WPS_CONTINUE;

View File

@ -802,6 +802,8 @@ void WpaGui::processMsg(char *msg)
} else if (str_match(pos, WPA_EVENT_EAP_METHOD)) {
if (strstr(pos, "(WSC)"))
wpsStatusText->setText("Registration started");
} else if (str_match(pos, WPS_EVENT_M2D)) {
wpsStatusText->setText("Registrar does not yet know PIN");
}
}

View File

@ -180,6 +180,27 @@ static int wpa_supplicant_wps_cred(void *ctx,
}
static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
struct wps_event_m2d *m2d)
{
wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_M2D
"dev_password_id=%d config_error=%d",
m2d->dev_password_id, m2d->config_error);
}
static void wpa_supplicant_wps_event(void *ctx, enum wps_event event,
union wps_event_data *data)
{
struct wpa_supplicant *wpa_s = ctx;
switch (event) {
case WPS_EV_M2D:
wpa_supplicant_wps_event_m2d(wpa_s, &data->m2d);
break;
}
}
u8 wpas_wps_get_req_type(struct wpa_ssid *ssid)
{
if (eap_is_wps_pbc_enrollee(&ssid->eap) ||
@ -361,6 +382,7 @@ int wpas_wps_init(struct wpa_supplicant *wpa_s)
return -1;
wps->cred_cb = wpa_supplicant_wps_cred;
wps->event_cb = wpa_supplicant_wps_event;
wps->cb_ctx = wpa_s;
wps->dev.device_name = wpa_s->conf->device_name;