const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout) { struct hostapd_data *hapd; unsigned int pin; char pin_txt[9]; if (wpa_s->ap_iface == NULL) return NULL; hapd = wpa_s->ap_iface->bss[0]; pin = wps_generate_pin(); os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin); os_free(hapd->conf->ap_pin); hapd->conf->ap_pin = os_strdup(pin_txt); if (hapd->conf->ap_pin == NULL) return NULL; wpas_wps_ap_pin_enable(wpa_s, timeout); return hapd->conf->ap_pin; }
int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin, int timeout) { struct hostapd_data *hapd; char pin_txt[9]; int ret; if (wpa_s->ap_iface == NULL) return -1; hapd = wpa_s->ap_iface->bss[0]; ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin); if (ret < 0 || ret >= (int) sizeof(pin_txt)) return -1; os_free(hapd->conf->ap_pin); hapd->conf->ap_pin = os_strdup(pin_txt); if (hapd->conf->ap_pin == NULL) return -1; wpas_wps_ap_pin_enable(wpa_s, timeout); return 0; }