在路由器开启WPS时,需要获取WPS的状态(成功,失败,超时,交叠),因此我们需要做如下修改:
1.在wps_registrar.c中加入如下函数,用于在tmp目录下写入文件,记录WPS状态。
static void wlan_report_wps(struct wps_registrar *reg, const char *value)
{
char fpath[64];
FILE *fp = NULL;
if (NULL == reg || NULL == value || '\0' == value[0])
{
return;
}
printf("reg->wps->dev.mac_addr = %02X:%02X:%02X:%02X:%02X:%02X\n",
reg->wps->dev.mac_addr[0], reg->wps->dev.mac_addr[1], reg->wps->dev.mac_addr[2],
reg->wps->dev.mac_addr[3], reg->wps->dev.mac_addr[4], reg->wps->dev.mac_addr[5]);
snprintf(fpath, sizeof(fpath), "/tmp/hostapd.%02X:%02X:%02X:%02X:%02X:%02X.wps",
reg->wps->dev.mac_addr[0], reg->wps->dev.mac_addr[1], reg->wps->dev.mac_addr[2],
reg->wps->dev.mac_addr[3], reg->wps->dev.mac_addr[4], reg->wps->dev.mac_addr[5]);
fp = fopen(fpath, "w");
if (NULL != fp)
{
fprintf(fp, "%s", value);
fclose(fp);
}
}
2.修改如下函数,用于写入状态。
static void wps_registrar_pbc_timeout(void *eloop_ctx, void *timeout_ctx)
{
struct wps_registrar *reg = eloop_ctx;
printf("wps_registrar_pbc_timeout\n");
wlan_report_wps(reg, "TIMEOUT");
wpa_printf(MSG_DEBUG, "WPS: PBC timed out - disable PBC mode");
wps_pbc_timeout_event(reg->wps);
wps_registrar_stop_pbc(reg);
}
int wps_registrar_button_pushed(struct wps_registrar *reg,
const u8 *p2p_dev_addr)
{
if (p2p_dev_addr == NULL &&
wps_registrar_pbc_overlap(reg, NULL, NULL)) {
wpa_printf(MSG_DEBUG, "WPS: PBC overlap - do not start PBC "
"mode");
wlan_report_wps(reg, "OVERLAP");
wps_pbc_overlap_event(reg->wps);
return -2;
}
wpa_printf(MSG_DEBUG, "WPS: Button pushed - PBC mode started");
reg->force_pbc_overlap = 0;
reg->selected_registrar = 1;
reg->pbc = 1;
if (p2p_dev_addr)
os_memcpy(reg->p2p_dev_addr, p2p_dev_addr, ETH_ALEN);
else
os_memset(reg->p2p_dev_addr, 0, ETH_ALEN);
wps_registrar_add_authorized_mac(reg,
(u8 *) "\xff\xff\xff\xff\xff\xff");
wps_registrar_selected_registrar_changed(reg, 0);
wps_pbc_active_event(reg->wps);
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
eloop_register_timeout(WPS_PBC_WALK_TIME, 0, wps_registrar_pbc_timeout,
reg, NULL);
return 0;
}
static void wps_registrar_pbc_completed(struct wps_registrar *reg)
{
printf("wps_registrar_pbc_completed\n");
wlan_report_wps(reg, "COMPLETED");
wpa_printf(MSG_DEBUG, "WPS: PBC completed - stopping PBC mode");
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
wps_registrar_stop_pbc(reg);
wps_pbc_disable_event(reg->wps);
}
static void wps_registrar_pin_completed(struct wps_registrar *reg)
{
printf("wps_registrar_pin_completed\n");
wlan_report_wps(reg, "COMPLETED");
wpa_printf(MSG_DEBUG, "WPS: PIN completed using internal Registrar");
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
reg->selected_registrar = 0;
wps_registrar_selected_registrar_changed(reg, 0);
}
int wps_registrar_wps_cancel(struct wps_registrar *reg)
{
#if 0
if (reg->pbc) {
wpa_printf(MSG_DEBUG, "WPS: PBC is set - cancelling it");
wps_registrar_pbc_timeout(reg, NULL);
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
return 1;
} else if (reg->selected_registrar) {
/* PIN Method */
wpa_printf(MSG_DEBUG, "WPS: PIN is set - cancelling it");
wps_registrar_pin_completed(reg);
wps_registrar_invalidate_wildcard_pin(reg, NULL, 0);
return 1;
}
#else
if (reg->pbc) {
wpa_printf(MSG_DEBUG, "WPS: PBC is set - cancelling it");
wlan_report_wps(reg, "CANCEL");
wps_pbc_timeout_event(reg->wps);
wps_registrar_stop_pbc(reg);
eloop_cancel_timeout(wps_registrar_pbc_timeout, reg, NULL);
return 1;
} else if (reg->selected_registrar) {
/* PIN Method */
wpa_printf(MSG_DEBUG, "WPS: PIN is set - cancelling it");
wlan_report_wps(reg, "CANCEL");
eloop_cancel_timeout(wps_registrar_set_selected_timeout, reg, NULL);
reg->selected_registrar = 0;
wps_registrar_selected_registrar_changed(reg,0);
wps_registrar_invalidate_wildcard_pin(reg, NULL, 0);
return 1;
}
#endif
return 0;
}
static void wps_registrar_set_selected_timeout(void *eloop_ctx,
void *timeout_ctx)
{
struct wps_registrar *reg = eloop_ctx;
wpa_printf(MSG_DEBUG, "wlan_report_wps TIMEOUT");
wlan_report_wps(reg, "TIMEOUT");
wpa_printf(MSG_DEBUG, "WPS: Selected Registrar timeout - "
"unselect internal Registrar");
reg->selected_registrar = 0;
reg->pbc = 0;
wps_registrar_selected_registrar_changed(reg, 0);
}