WPS ER: Add command for configuring an AP
wps_er_config can now be used to configure an AP. It is similar to wps_er_learn, but instead of only learning the current AP settings, it continues to send M8 with the new settings for the AP.
This commit is contained in:
parent
3085b8052e
commit
7d6640a62c
7 changed files with 252 additions and 7 deletions
|
@ -737,6 +737,8 @@ void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
|
|||
int wps_er_pbc(struct wps_er *er, const u8 *uuid);
|
||||
int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
|
||||
size_t pin_len);
|
||||
int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *pin,
|
||||
size_t pin_len, const struct wps_credential *cred);
|
||||
|
||||
int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
|
||||
char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
|
||||
|
|
|
@ -1501,10 +1501,26 @@ static void wps_er_ap_put_message(struct wps_er_ap *ap,
|
|||
static void wps_er_ap_process(struct wps_er_ap *ap, struct wpabuf *msg)
|
||||
{
|
||||
enum wps_process_res res;
|
||||
struct wps_parse_attr attr;
|
||||
enum wsc_op_code op_code;
|
||||
|
||||
res = wps_process_msg(ap->wps, WSC_MSG, msg);
|
||||
op_code = WSC_MSG;
|
||||
if (wps_parse_msg(msg, &attr) == 0 && attr.msg_type) {
|
||||
switch (*attr.msg_type) {
|
||||
case WPS_WSC_ACK:
|
||||
op_code = WSC_ACK;
|
||||
break;
|
||||
case WPS_WSC_NACK:
|
||||
op_code = WSC_NACK;
|
||||
break;
|
||||
case WPS_WSC_DONE:
|
||||
op_code = WSC_Done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
res = wps_process_msg(ap->wps, op_code, msg);
|
||||
if (res == WPS_CONTINUE) {
|
||||
enum wsc_op_code op_code;
|
||||
struct wpabuf *next = wps_get_msg(ap->wps, &op_code);
|
||||
if (next) {
|
||||
wps_er_ap_put_message(ap, next);
|
||||
|
@ -1675,3 +1691,64 @@ int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void wps_er_ap_config_m1(struct wps_er_ap *ap, struct wpabuf *m1)
|
||||
{
|
||||
struct wps_config cfg;
|
||||
|
||||
if (ap->wps) {
|
||||
wpa_printf(MSG_DEBUG, "WPS ER: Protocol run already in "
|
||||
"progress with this AP");
|
||||
return;
|
||||
}
|
||||
|
||||
os_memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.wps = ap->er->wps;
|
||||
cfg.registrar = 1;
|
||||
cfg.new_ap_settings = ap->ap_settings;
|
||||
ap->wps = wps_init(&cfg);
|
||||
if (ap->wps == NULL)
|
||||
return;
|
||||
ap->wps->ap_settings_cb = NULL;
|
||||
ap->wps->ap_settings_cb_ctx = NULL;
|
||||
|
||||
wps_er_ap_process(ap, m1);
|
||||
}
|
||||
|
||||
|
||||
int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *pin,
|
||||
size_t pin_len, const struct wps_credential *cred)
|
||||
{
|
||||
struct wps_er_ap *ap;
|
||||
|
||||
if (er == NULL)
|
||||
return -1;
|
||||
|
||||
ap = wps_er_ap_get(er, NULL, uuid);
|
||||
if (ap == NULL) {
|
||||
wpa_printf(MSG_DEBUG, "WPS ER: AP not found for config "
|
||||
"request");
|
||||
return -1;
|
||||
}
|
||||
if (ap->wps) {
|
||||
wpa_printf(MSG_DEBUG, "WPS ER: Pending operation ongoing "
|
||||
"with the AP - cannot start config");
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_free(ap->ap_settings);
|
||||
ap->ap_settings = os_malloc(sizeof(*cred));
|
||||
if (ap->ap_settings == NULL)
|
||||
return -1;
|
||||
os_memcpy(ap->ap_settings, cred, sizeof(*cred));
|
||||
ap->ap_settings->cred_attr = NULL;
|
||||
|
||||
if (wps_er_send_get_device_info(ap, wps_er_ap_config_m1) < 0)
|
||||
return -1;
|
||||
|
||||
/* TODO: add PIN without SetSelectedRegistrar trigger to all APs */
|
||||
wps_registrar_add_pin(er->wps->registrar, uuid, pin, pin_len, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue