void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_message msg; size_t g; wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Received Device Discoverability Request from " MACSTR " (freq=%d)", MAC2STR(sa), rx_freq); if (p2p_parse(data, len, &msg)) return; if (msg.dialog_token == 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Invalid Dialog Token 0 (must be nonzero) in " "Device Discoverability Request"); p2p_send_dev_disc_resp(p2p, msg.dialog_token, sa, rx_freq, P2P_SC_FAIL_INVALID_PARAMS); p2p_parse_free(&msg); return; } if (msg.device_id == NULL) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: P2P Device ID attribute missing from Device " "Discoverability Request"); p2p_send_dev_disc_resp(p2p, msg.dialog_token, sa, rx_freq, P2P_SC_FAIL_INVALID_PARAMS); p2p_parse_free(&msg); return; } for (g = 0; g < p2p->num_groups; g++) { if (p2p_group_go_discover(p2p->groups[g], msg.device_id, sa, rx_freq) == 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Scheduled " "GO Discoverability Request for the target " "device"); /* * P2P group code will use a callback to indicate TX * status, so that we can reply to the request once the * target client has acknowledged the request or it has * timed out. */ p2p->pending_dev_disc_dialog_token = msg.dialog_token; os_memcpy(p2p->pending_dev_disc_addr, sa, ETH_ALEN); p2p->pending_dev_disc_freq = rx_freq; p2p_parse_free(&msg); return; } } wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Requested client " "was not found in any group or did not support client " "discoverability"); p2p_send_dev_disc_resp(p2p, msg.dialog_token, sa, rx_freq, P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE); p2p_parse_free(&msg); }
void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_device *dev; struct p2p_message msg; wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Received Invitation Response from " MACSTR, MAC2STR(sa)); dev = p2p_get_device(p2p, sa); if (dev == NULL) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore Invitation Response from unknown peer " MACSTR, MAC2STR(sa)); return; } if (dev != p2p->invite_peer) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore unexpected Invitation Response from peer " MACSTR, MAC2STR(sa)); return; } /* Framework use the valid intended address to broadcast the connected status */ os_memcpy(dev->intended_addr, sa, ETH_ALEN); if (p2p_parse(data, len, &msg)) return; if (!msg.status) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Mandatory Status attribute missing in " "Invitation Response from " MACSTR, MAC2STR(sa)); p2p_parse_free(&msg); return; } if (p2p->cfg->invitation_result) p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status, msg.group_bssid); p2p_parse_free(&msg); p2p_clear_timeout(p2p); p2p_set_state(p2p, P2P_IDLE); p2p->invite_peer = NULL; }
void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_message msg; struct p2p_device *dev; int freq; enum p2p_status_code reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; struct wpabuf *resp; u32 adv_id = 0; struct p2ps_advertisement *p2ps_adv = NULL; u8 conncap = P2PS_SETUP_NEW; u8 auto_accept = 0; u32 session_id = 0; u8 session_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; u8 adv_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 }; const u8 *group_mac; int passwd_id = DEV_PW_DEFAULT; u16 config_methods; u16 allowed_config_methods = WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD; struct p2ps_feature_capab resp_fcap = { 0, 0 }; struct p2ps_feature_capab *req_fcap = NULL; u8 remote_conncap; u16 method; if (p2p_parse(data, len, &msg)) return; p2p_dbg(p2p, "Received Provision Discovery Request from " MACSTR " with config methods 0x%x (freq=%d)", MAC2STR(sa), msg.wps_config_methods, rx_freq); group_mac = msg.intended_addr; dev = p2p_get_device(p2p, sa); if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { p2p_dbg(p2p, "Provision Discovery Request from unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, 0)) { p2p_dbg(p2p, "Provision Discovery Request add device failed " MACSTR, MAC2STR(sa)); goto out; } if (!dev) { dev = p2p_get_device(p2p, sa); if (!dev) { p2p_dbg(p2p, "Provision Discovery device not found " MACSTR, MAC2STR(sa)); goto out; } } } else if (msg.wfd_subelems) { wpabuf_free(dev->info.wfd_subelems); dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems); } if (!msg.adv_id) { allowed_config_methods |= WPS_CONFIG_PUSHBUTTON; if (!(msg.wps_config_methods & allowed_config_methods)) { p2p_dbg(p2p, "Unsupported Config Methods in Provision Discovery Request"); goto out; } /* Legacy (non-P2PS) - Unknown groups allowed for P2PS */ if (msg.group_id) { size_t i; for (i = 0; i < p2p->num_groups; i++) { if (p2p_group_is_group_id_match( p2p->groups[i], msg.group_id, msg.group_id_len)) break; } if (i == p2p->num_groups) { p2p_dbg(p2p, "PD request for unknown P2P Group ID - reject"); goto out; } } } else { allowed_config_methods |= WPS_CONFIG_P2PS; /* * Set adv_id here, so in case of an error, a P2PS PD Response * will be sent. */ adv_id = WPA_GET_LE32(msg.adv_id); if (p2ps_validate_pd_req(p2p, &msg, sa) < 0) { reject = P2P_SC_FAIL_INVALID_PARAMS; goto out; } req_fcap = (struct p2ps_feature_capab *) msg.feature_cap; os_memcpy(session_mac, msg.session_mac, ETH_ALEN); os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN); session_id = WPA_GET_LE32(msg.session_id); if (msg.conn_cap) conncap = *msg.conn_cap; /* * We need to verify a P2PS config methog in an initial PD * request or in a follow-on PD request with the status * SUCCESS_DEFERRED. */ if ((!msg.status || *msg.status == P2P_SC_SUCCESS_DEFERRED) && !(msg.wps_config_methods & allowed_config_methods)) { p2p_dbg(p2p, "Unsupported Config Methods in Provision Discovery Request"); goto out; } /* * TODO: since we don't support multiple PD, reject PD request * if we are in the middle of P2PS PD with some other peer */ } dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD | P2P_DEV_PD_PEER_P2PS); if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " requested us to show a PIN on display", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_KEYPAD; passwd_id = DEV_PW_USER_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " requested us to write its PIN using keypad", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_DISPLAY; passwd_id = DEV_PW_REGISTRAR_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) { p2p_dbg(p2p, "Peer " MACSTR " requesting P2PS PIN", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_P2PS; passwd_id = DEV_PW_P2PS_DEFAULT; } /* Remove stale persistent groups */ if (p2p->cfg->remove_stale_groups) { p2p->cfg->remove_stale_groups( p2p->cfg->cb_ctx, dev->info.p2p_device_addr, msg.persistent_dev, msg.persistent_ssid, msg.persistent_ssid_len); } reject = P2P_SC_SUCCESS; /* * End of a legacy P2P PD Request processing, from this point continue * with P2PS one. */ if (!msg.adv_id) goto out; remote_conncap = conncap; if (!msg.status) { unsigned int forced_freq, pref_freq; if (os_memcmp(p2p->cfg->dev_addr, msg.adv_mac, ETH_ALEN)) { p2p_dbg(p2p, "P2PS PD adv mac does not match the local one"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } p2ps_adv = p2p_service_p2ps_id(p2p, adv_id); if (!p2ps_adv) { p2p_dbg(p2p, "P2PS PD invalid adv_id=0x%X", adv_id); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } p2p_dbg(p2p, "adv_id: 0x%X, p2ps_adv: %p", adv_id, p2ps_adv); auto_accept = p2ps_adv->auto_accept; conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx, conncap, auto_accept, &forced_freq, &pref_freq); p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d", auto_accept, remote_conncap, conncap); p2p_prepare_channel(p2p, dev, forced_freq, pref_freq, 0); resp_fcap.cpt = p2ps_own_preferred_cpt(p2ps_adv->cpt_priority, req_fcap->cpt); p2p_dbg(p2p, "cpt: service:0x%x remote:0x%x result:0x%x", p2ps_adv->cpt_mask, req_fcap->cpt, resp_fcap.cpt); if (!resp_fcap.cpt) { p2p_dbg(p2p, "Incompatible P2PS feature capability CPT bitmask"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (p2ps_adv->config_methods && !(msg.wps_config_methods & p2ps_adv->config_methods)) { p2p_dbg(p2p, "Unsupported config methods in Provision Discovery Request (own=0x%x peer=0x%x)", p2ps_adv->config_methods, msg.wps_config_methods); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (!p2ps_adv->state) { p2p_dbg(p2p, "P2PS state unavailable"); reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; } else if (!conncap) { p2p_dbg(p2p, "Conncap resolution failed"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Keypad - always defer"); auto_accept = 0; } if ((remote_conncap & (P2PS_SETUP_NEW | P2PS_SETUP_CLIENT) || msg.persistent_dev) && conncap != P2PS_SETUP_NEW && msg.channel_list && msg.channel_list_len && p2p_peer_channels_check(p2p, &p2p->channels, dev, msg.channel_list, msg.channel_list_len) < 0) { p2p_dbg(p2p, "No common channels - force deferred flow"); auto_accept = 0; } if (((remote_conncap & P2PS_SETUP_GROUP_OWNER) || msg.persistent_dev) && msg.operating_channel) { struct p2p_channels intersect; /* * There are cases where only the operating channel is * provided. This requires saving the channel as the * supported channel list, and verifying that it is * supported. */ if (dev->channels.reg_classes == 0 || !p2p_channels_includes(&dev->channels, msg.operating_channel[3], msg.operating_channel[4])) { struct p2p_channels *ch = &dev->channels; os_memset(ch, 0, sizeof(*ch)); ch->reg_class[0].reg_class = msg.operating_channel[3]; ch->reg_class[0].channel[0] = msg.operating_channel[4]; ch->reg_class[0].channels = 1; ch->reg_classes = 1; } p2p_channels_intersect(&p2p->channels, &dev->channels, &intersect); if (intersect.reg_classes == 0) { p2p_dbg(p2p, "No common channels - force deferred flow"); auto_accept = 0; } } if (auto_accept || reject != P2P_SC_SUCCESS) { struct p2ps_provision *tmp; if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id, msg.wps_config_methods, session_mac, adv_mac) < 0) { reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; goto out; } tmp = p2p->p2ps_prov; tmp->force_freq = forced_freq; tmp->pref_freq = pref_freq; if (conncap) { tmp->conncap = conncap; tmp->status = P2P_SC_SUCCESS; } else { tmp->conncap = auto_accept; tmp->status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (reject != P2P_SC_SUCCESS) goto out; } } if (!msg.status && !auto_accept && (!p2p->p2ps_prov || p2p->p2ps_prov->adv_id != adv_id)) { struct p2ps_provision *tmp; if (!conncap) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id, msg.wps_config_methods, session_mac, adv_mac) < 0) { reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; goto out; } tmp = p2p->p2ps_prov; reject = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; tmp->status = reject; } /* Not a P2PS Follow-on PD */ if (!msg.status) goto out; if (*msg.status && *msg.status != P2P_SC_SUCCESS_DEFERRED) { reject = *msg.status; goto out; } if (*msg.status != P2P_SC_SUCCESS_DEFERRED || !p2p->p2ps_prov) goto out; if (p2p->p2ps_prov->adv_id != adv_id || os_memcmp(p2p->p2ps_prov->adv_mac, msg.adv_mac, ETH_ALEN)) { p2p_dbg(p2p, "P2PS Follow-on PD with mismatch Advertisement ID/MAC"); goto out; } if (p2p->p2ps_prov->session_id != session_id || os_memcmp(p2p->p2ps_prov->session_mac, msg.session_mac, ETH_ALEN)) { p2p_dbg(p2p, "P2PS Follow-on PD with mismatch Session ID/MAC"); goto out; } method = p2p->p2ps_prov->method; conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx, remote_conncap, p2p->p2ps_prov->conncap, &p2p->p2ps_prov->force_freq, &p2p->p2ps_prov->pref_freq); resp_fcap.cpt = p2ps_own_preferred_cpt(p2p->p2ps_prov->cpt_priority, req_fcap->cpt); p2p_dbg(p2p, "cpt: local:0x%x remote:0x%x result:0x%x", p2p->p2ps_prov->cpt_mask, req_fcap->cpt, resp_fcap.cpt); p2p_prepare_channel(p2p, dev, p2p->p2ps_prov->force_freq, p2p->p2ps_prov->pref_freq, 0); /* * Ensure that if we asked for PIN originally, our method is consistent * with original request. */ if (method & WPS_CONFIG_DISPLAY) method = WPS_CONFIG_KEYPAD; else if (method & WPS_CONFIG_KEYPAD) method = WPS_CONFIG_DISPLAY; if (!conncap || !(msg.wps_config_methods & method)) { /* * Reject this "Deferred Accept* * if incompatible conncap or method */ reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (!resp_fcap.cpt) { p2p_dbg(p2p, "Incompatible P2PS feature capability CPT bitmask"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if ((remote_conncap & (P2PS_SETUP_NEW | P2PS_SETUP_CLIENT) || msg.persistent_dev) && conncap != P2PS_SETUP_NEW && msg.channel_list && msg.channel_list_len && p2p_peer_channels_check(p2p, &p2p->channels, dev, msg.channel_list, msg.channel_list_len) < 0) { p2p_dbg(p2p, "No common channels in Follow-On Provision Discovery Request"); reject = P2P_SC_FAIL_NO_COMMON_CHANNELS; } else { reject = P2P_SC_SUCCESS; } dev->oper_freq = 0; if (reject == P2P_SC_SUCCESS || reject == P2P_SC_SUCCESS_DEFERRED) { u8 tmp; if (msg.operating_channel) dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3], msg.operating_channel[4]); if ((conncap & P2PS_SETUP_GROUP_OWNER) && p2p_go_select_channel(p2p, dev, &tmp) < 0) reject = P2P_SC_FAIL_NO_COMMON_CHANNELS; } p2p->p2ps_prov->status = reject; p2p->p2ps_prov->conncap = conncap; out: if (reject == P2P_SC_SUCCESS || reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) config_methods = msg.wps_config_methods; else config_methods = 0; /* * Send PD Response for an initial PD Request or for follow-on * PD Request with P2P_SC_SUCCESS_DEFERRED status. */ if (!msg.status || *msg.status == P2P_SC_SUCCESS_DEFERRED) { resp = p2p_build_prov_disc_resp(p2p, dev, msg.dialog_token, reject, config_methods, adv_id, msg.group_id, msg.group_id_len, msg.persistent_ssid, msg.persistent_ssid_len, (const u8 *) &resp_fcap, sizeof(resp_fcap)); if (!resp) { p2p_parse_free(&msg); return; } p2p_dbg(p2p, "Sending Provision Discovery Response"); if (rx_freq > 0) freq = rx_freq; else freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); if (freq < 0) { p2p_dbg(p2p, "Unknown regulatory class/channel"); wpabuf_free(resp); p2p_parse_free(&msg); return; } p2p->pending_action_state = P2P_PENDING_PD_RESPONSE; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 200) < 0) p2p_dbg(p2p, "Failed to send Action frame"); else p2p->send_action_in_progress = 1; wpabuf_free(resp); } if (!dev) { p2p_parse_free(&msg); return; } freq = 0; if (reject == P2P_SC_SUCCESS && conncap == P2PS_SETUP_GROUP_OWNER) { freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel); if (freq < 0) freq = 0; } if (!p2p->cfg->p2ps_prov_complete) { /* Don't emit anything */ } else if (msg.status && *msg.status != P2P_SC_SUCCESS && *msg.status != P2P_SC_SUCCESS_DEFERRED) { reject = *msg.status; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject, sa, adv_mac, session_mac, NULL, adv_id, session_id, 0, 0, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, NULL, 0, freq); } else if (msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { p2p->p2ps_prov->status = reject; p2p->p2ps_prov->conncap = conncap; if (reject != P2P_SC_SUCCESS) p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject, sa, adv_mac, session_mac, NULL, adv_id, session_id, conncap, 0, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, NULL, 0, freq); else p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap), freq); } else if (msg.status && p2p->p2ps_prov) { p2p->p2ps_prov->status = P2P_SC_SUCCESS; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap), freq); } else if (msg.status) { } else if (auto_accept && reject == P2P_SC_SUCCESS) { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap), freq); } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && (!msg.session_info || !msg.session_info_len)) { p2p->p2ps_prov->method = msg.wps_config_methods; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 1, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap), freq); } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { size_t buf_len = msg.session_info_len; char *buf = os_malloc(2 * buf_len + 1); if (buf) { p2p->p2ps_prov->method = msg.wps_config_methods; utf8_escape((char *) msg.session_info, buf_len, buf, 2 * buf_len + 1); p2p->cfg->p2ps_prov_complete( p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 1, buf, (const u8 *) &resp_fcap, sizeof(resp_fcap), freq); os_free(buf); } } /* * prov_disc_req callback is used to generate P2P-PROV-DISC-ENTER-PIN, * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events. * Call it either on legacy P2P PD or on P2PS PD only if we need to * enter/show PIN. * * The callback is called in the following cases: * 1. Legacy P2P PD request, response status SUCCESS * 2. P2PS advertiser, method: DISPLAY, autoaccept: TRUE, * response status: SUCCESS * 3. P2PS advertiser, method DISPLAY, autoaccept: FALSE, * response status: INFO_CURRENTLY_UNAVAILABLE * 4. P2PS advertiser, method: KEYPAD, autoaccept==any, * response status: INFO_CURRENTLY_UNAVAILABLE * 5. P2PS follow-on with SUCCESS_DEFERRED, * advertiser role: DISPLAY, autoaccept: FALSE, * seeker: KEYPAD, response status: SUCCESS */ if (p2p->cfg->prov_disc_req && ((reject == P2P_SC_SUCCESS && !msg.adv_id) || (!msg.status && (reject == P2P_SC_SUCCESS || reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) && passwd_id == DEV_PW_USER_SPECIFIED) || (!msg.status && reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && passwd_id == DEV_PW_REGISTRAR_SPECIFIED) || (reject == P2P_SC_SUCCESS && msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED && passwd_id == DEV_PW_REGISTRAR_SPECIFIED))) { const u8 *dev_addr = sa; if (msg.p2p_device_addr) dev_addr = msg.p2p_device_addr; p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa, msg.wps_config_methods, dev_addr, msg.pri_dev_type, msg.device_name, msg.config_methods, msg.capability ? msg.capability[0] : 0, msg.capability ? msg.capability[1] : 0, msg.group_id, msg.group_id_len); } if (reject == P2P_SC_SUCCESS) { switch (config_methods) { case WPS_CONFIG_DISPLAY: dev->wps_prov_info = WPS_CONFIG_KEYPAD; break; case WPS_CONFIG_KEYPAD: dev->wps_prov_info = WPS_CONFIG_DISPLAY; break; case WPS_CONFIG_PUSHBUTTON: dev->wps_prov_info = WPS_CONFIG_PUSHBUTTON; break; case WPS_CONFIG_P2PS: dev->wps_prov_info = WPS_CONFIG_P2PS; break; default: dev->wps_prov_info = 0; break; } if (msg.intended_addr) os_memcpy(dev->interface_addr, msg.intended_addr, ETH_ALEN); } p2p_parse_free(&msg); }
void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_message msg; struct p2p_device *dev; u16 report_config_methods = 0, req_config_methods; u8 status = P2P_SC_SUCCESS; u32 adv_id = 0; u8 conncap = P2PS_SETUP_NEW; u8 adv_mac[ETH_ALEN]; const u8 *group_mac; int passwd_id = DEV_PW_DEFAULT; int p2ps_seeker; if (p2p_parse(data, len, &msg)) return; if (p2p->p2ps_prov && p2p_validate_p2ps_pd_resp(p2p, &msg)) { p2p_parse_free(&msg); return; } /* Parse the P2PS members present */ if (msg.status) status = *msg.status; group_mac = msg.intended_addr; if (msg.adv_mac) os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN); else os_memset(adv_mac, 0, ETH_ALEN); if (msg.adv_id) adv_id = WPA_GET_LE32(msg.adv_id); if (msg.conn_cap) { conncap = *msg.conn_cap; /* Switch bits to local relative */ switch (conncap) { case P2PS_SETUP_GROUP_OWNER: conncap = P2PS_SETUP_CLIENT; break; case P2PS_SETUP_CLIENT: conncap = P2PS_SETUP_GROUP_OWNER; break; } } p2p_dbg(p2p, "Received Provision Discovery Response from " MACSTR " with config methods 0x%x", MAC2STR(sa), msg.wps_config_methods); dev = p2p_get_device(p2p, sa); if (dev == NULL || !dev->req_config_methods) { p2p_dbg(p2p, "Ignore Provision Discovery Response from " MACSTR " with no pending request", MAC2STR(sa)); p2p_parse_free(&msg); return; } if (dev->dialog_token != msg.dialog_token) { p2p_dbg(p2p, "Ignore Provision Discovery Response with unexpected Dialog Token %u (expected %u)", msg.dialog_token, dev->dialog_token); p2p_parse_free(&msg); return; } if (p2p->pending_action_state == P2P_PENDING_PD) { os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN); p2p->pending_action_state = P2P_NO_PENDING_ACTION; } p2ps_seeker = p2p->p2ps_prov && p2p->p2ps_prov->pd_seeker; /* * Use a local copy of the requested config methods since * p2p_reset_pending_pd() can clear this in the peer entry. */ req_config_methods = dev->req_config_methods; /* * If the response is from the peer to whom a user initiated request * was sent earlier, we reset that state info here. */ if (p2p->user_initiated_pd && os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0) p2p_reset_pending_pd(p2p); if (msg.wps_config_methods != req_config_methods) { p2p_dbg(p2p, "Peer rejected our Provision Discovery Request (received config_methods 0x%x expected 0x%x", msg.wps_config_methods, req_config_methods); if (p2p->cfg->prov_disc_fail) p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_REJECTED, adv_id, adv_mac, NULL); p2p_parse_free(&msg); p2ps_prov_free(p2p); goto out; } report_config_methods = req_config_methods; dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD | P2P_DEV_PD_PEER_P2PS); if (req_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " accepted to show a PIN on display", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_DISPLAY; passwd_id = DEV_PW_REGISTRAR_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " accepted to write our PIN using keypad", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_KEYPAD; passwd_id = DEV_PW_USER_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) { p2p_dbg(p2p, "Peer " MACSTR " accepted P2PS PIN", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_P2PS; passwd_id = DEV_PW_P2PS_DEFAULT; } if ((status == P2P_SC_SUCCESS || status == P2P_SC_SUCCESS_DEFERRED) && p2p->p2ps_prov) { dev->oper_freq = 0; /* * Save the reported channel list and operating frequency. * Note that the specification mandates that the responder * should include in the channel list only channels reported by * the initiator, so this is only a sanity check, and if this * fails the flow would continue, although it would probably * fail. Same is true for the operating channel. */ if (msg.channel_list && msg.channel_list_len && p2p_peer_channels_check(p2p, &p2p->channels, dev, msg.channel_list, msg.channel_list_len) < 0) p2p_dbg(p2p, "P2PS PD Response - no common channels"); if (msg.operating_channel) { if (p2p_channels_includes(&p2p->channels, msg.operating_channel[3], msg.operating_channel[4]) && p2p_channels_includes(&dev->channels, msg.operating_channel[3], msg.operating_channel[4])) { dev->oper_freq = p2p_channel_to_freq( msg.operating_channel[3], msg.operating_channel[4]); } else { p2p_dbg(p2p, "P2PS PD Response - invalid operating channel"); } } if (p2p->cfg->p2ps_prov_complete) { int freq = 0; if (conncap == P2PS_SETUP_GROUP_OWNER) { u8 tmp; /* * Re-select the operating channel as it is * possible that original channel is no longer * valid. This should not really fail. */ if (p2p_go_select_channel(p2p, dev, &tmp) < 0) p2p_dbg(p2p, "P2PS PD channel selection failed"); freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel); if (freq < 0) freq = 0; } p2p->cfg->p2ps_prov_complete( p2p->cfg->cb_ctx, status, sa, adv_mac, p2p->p2ps_prov->session_mac, group_mac, adv_id, p2p->p2ps_prov->session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 1, 0, NULL, msg.feature_cap, msg.feature_cap_len, freq); } p2ps_prov_free(p2p); } else if (status != P2P_SC_SUCCESS && status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && status != P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { if (p2p->cfg->p2ps_prov_complete) p2p->cfg->p2ps_prov_complete( p2p->cfg->cb_ctx, status, sa, adv_mac, p2p->p2ps_prov->session_mac, group_mac, adv_id, p2p->p2ps_prov->session_id, 0, 0, NULL, 0, 1, 0, NULL, NULL, 0, 0); p2ps_prov_free(p2p); } if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { if (p2p->cfg->remove_stale_groups) { p2p->cfg->remove_stale_groups(p2p->cfg->cb_ctx, dev->info.p2p_device_addr, NULL, NULL, 0); } if (msg.session_info && msg.session_info_len) { size_t info_len = msg.session_info_len; char *deferred_sess_resp = os_malloc(2 * info_len + 1); if (!deferred_sess_resp) { p2p_parse_free(&msg); p2ps_prov_free(p2p); goto out; } utf8_escape((char *) msg.session_info, info_len, deferred_sess_resp, 2 * info_len + 1); if (p2p->cfg->prov_disc_fail) p2p->cfg->prov_disc_fail( p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_INFO_UNAVAILABLE, adv_id, adv_mac, deferred_sess_resp); os_free(deferred_sess_resp); } else if (p2p->cfg->prov_disc_fail) p2p->cfg->prov_disc_fail( p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_INFO_UNAVAILABLE, adv_id, adv_mac, NULL); } else if (status != P2P_SC_SUCCESS) { p2p_dbg(p2p, "Peer rejected our Provision Discovery Request"); if (p2p->cfg->prov_disc_fail) p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_REJECTED, adv_id, adv_mac, NULL); p2p_parse_free(&msg); p2ps_prov_free(p2p); goto out; } /* Store the provisioning info */ dev->wps_prov_info = msg.wps_config_methods; if (msg.intended_addr) os_memcpy(dev->interface_addr, msg.intended_addr, ETH_ALEN); p2p_parse_free(&msg); out: dev->req_config_methods = 0; p2p->cfg->send_action_done(p2p->cfg->cb_ctx); if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) { p2p_dbg(p2p, "Start GO Neg after the PD-before-GO-Neg workaround with " MACSTR, MAC2STR(dev->info.p2p_device_addr)); dev->flags &= ~P2P_DEV_PD_BEFORE_GO_NEG; p2p_connect_send(p2p, dev); return; } /* * prov_disc_resp callback is used to generate P2P-PROV-DISC-ENTER-PIN, * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events. * Call it only for a legacy P2P PD or for P2PS PD scenarios where * show/enter PIN events are needed. * * The callback is called in the following cases: * 1. Legacy P2P PD response with a status SUCCESS * 2. P2PS, advertiser method: DISPLAY, autoaccept: true, * response status: SUCCESS, local method KEYPAD * 3. P2PS, advertiser method: KEYPAD,Seeker side, * response status: INFO_CURRENTLY_UNAVAILABLE, * local method: DISPLAY */ if (p2p->cfg->prov_disc_resp && ((status == P2P_SC_SUCCESS && !adv_id) || (p2ps_seeker && status == P2P_SC_SUCCESS && passwd_id == DEV_PW_REGISTRAR_SPECIFIED) || (p2ps_seeker && status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && passwd_id == DEV_PW_USER_SPECIFIED))) p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa, report_config_methods); if (p2p->state == P2P_PD_DURING_FIND) { p2p_clear_timeout(p2p); p2p_continue_find(p2p); } }
void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_message msg; struct p2p_device *dev; u16 report_config_methods = 0, req_config_methods; int success = 0; if (p2p_parse(data, len, &msg)) return; p2p_dbg(p2p, "Received Provision Discovery Response from " MACSTR " with config methods 0x%x", MAC2STR(sa), msg.wps_config_methods); dev = p2p_get_device(p2p, sa); if (dev == NULL || !dev->req_config_methods) { p2p_dbg(p2p, "Ignore Provision Discovery Response from " MACSTR " with no pending request", MAC2STR(sa)); p2p_parse_free(&msg); return; } if (dev->dialog_token != msg.dialog_token) { p2p_dbg(p2p, "Ignore Provision Discovery Response with unexpected Dialog Token %u (expected %u)", msg.dialog_token, dev->dialog_token); p2p_parse_free(&msg); return; } if (p2p->pending_action_state == P2P_PENDING_PD) { os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN); p2p->pending_action_state = P2P_NO_PENDING_ACTION; } /* * Use a local copy of the requested config methods since * p2p_reset_pending_pd() can clear this in the peer entry. */ req_config_methods = dev->req_config_methods; /* * If the response is from the peer to whom a user initiated request * was sent earlier, we reset that state info here. */ if (p2p->user_initiated_pd && os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0) p2p_reset_pending_pd(p2p); if (msg.wps_config_methods != req_config_methods) { p2p_dbg(p2p, "Peer rejected our Provision Discovery Request (received config_methods 0x%x expected 0x%x", msg.wps_config_methods, req_config_methods); if (p2p->cfg->prov_disc_fail) p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_REJECTED); p2p_parse_free(&msg); goto out; } report_config_methods = req_config_methods; dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD); if (req_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " accepted to show a PIN on display", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_DISPLAY; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " accepted to write our PIN using keypad", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_KEYPAD; } /* Store the provisioning info */ dev->wps_prov_info = msg.wps_config_methods; p2p_parse_free(&msg); success = 1; out: dev->req_config_methods = 0; p2p->cfg->send_action_done(p2p->cfg->cb_ctx); if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) { p2p_dbg(p2p, "Start GO Neg after the PD-before-GO-Neg workaround with " MACSTR, MAC2STR(dev->info.p2p_device_addr)); dev->flags &= ~P2P_DEV_PD_BEFORE_GO_NEG; p2p_connect_send(p2p, dev); return; } if (success && p2p->cfg->prov_disc_resp) p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa, report_config_methods); if (p2p->state == P2P_PD_DURING_FIND) { p2p_clear_timeout(p2p); p2p_continue_find(p2p); } }
void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_message msg; struct p2p_device *dev; int freq; int reject = 1; struct wpabuf *resp; if (p2p_parse(data, len, &msg)) return; p2p_dbg(p2p, "Received Provision Discovery Request from " MACSTR " with config methods 0x%x (freq=%d)", MAC2STR(sa), msg.wps_config_methods, rx_freq); dev = p2p_get_device(p2p, sa); if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { p2p_dbg(p2p, "Provision Discovery Request from unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, 0)) { p2p_dbg(p2p, "Provision Discovery Request add device failed " MACSTR, MAC2STR(sa)); } } else if (msg.wfd_subelems) { wpabuf_free(dev->info.wfd_subelems); dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems); } if (!(msg.wps_config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_PUSHBUTTON))) { p2p_dbg(p2p, "Unsupported Config Methods in Provision Discovery Request"); goto out; } if (msg.group_id) { size_t i; for (i = 0; i < p2p->num_groups; i++) { if (p2p_group_is_group_id_match(p2p->groups[i], msg.group_id, msg.group_id_len)) break; } if (i == p2p->num_groups) { p2p_dbg(p2p, "PD request for unknown P2P Group ID - reject"); goto out; } } if (dev) dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD); if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " requested us to show a PIN on display", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_KEYPAD; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " requested us to write its PIN using keypad", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_DISPLAY; } reject = 0; out: resp = p2p_build_prov_disc_resp(p2p, msg.dialog_token, reject ? 0 : msg.wps_config_methods, msg.group_id, msg.group_id_len); if (resp == NULL) { p2p_parse_free(&msg); return; } p2p_dbg(p2p, "Sending Provision Discovery Response"); if (rx_freq > 0) freq = rx_freq; else freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); if (freq < 0) { p2p_dbg(p2p, "Unknown regulatory class/channel"); wpabuf_free(resp); p2p_parse_free(&msg); return; } p2p->pending_action_state = P2P_NO_PENDING_ACTION; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { p2p_dbg(p2p, "Failed to send Action frame"); } else p2p->send_action_in_progress = 1; wpabuf_free(resp); if (!reject && p2p->cfg->prov_disc_req) { const u8 *dev_addr = sa; if (msg.p2p_device_addr) dev_addr = msg.p2p_device_addr; p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa, msg.wps_config_methods, dev_addr, msg.pri_dev_type, msg.device_name, msg.config_methods, msg.capability ? msg.capability[0] : 0, msg.capability ? msg.capability[1] : 0, msg.group_id, msg.group_id_len); } p2p_parse_free(&msg); }
void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_message msg; struct p2p_device *dev; u16 report_config_methods = 0; if (p2p_parse(data, len, &msg)) return; wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Received Provisioning Discovery Response from " MACSTR " with config methods 0x%x", MAC2STR(sa), msg.wps_config_methods); dev = p2p_get_device(p2p, sa); if (dev == NULL || !dev->req_config_methods) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore Provisioning Discovery Response from " MACSTR " with no pending request", MAC2STR(sa)); p2p_parse_free(&msg); return; } if (p2p->pending_action_state == P2P_PENDING_PD) { os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN); p2p->pending_action_state = P2P_NO_PENDING_ACTION; } if (dev->dialog_token != msg.dialog_token) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore Provisioning Discovery Response with " "unexpected Dialog Token %u (expected %u)", msg.dialog_token, dev->dialog_token); p2p_parse_free(&msg); return; } /* * If the response is from the peer to whom a user initiated request * was sent earlier, we reset that state info here. */ if (p2p->user_initiated_pd && os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0) p2p_reset_pending_pd(p2p); if (msg.wps_config_methods != dev->req_config_methods) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer rejected " "our Provisioning Discovery Request"); if (p2p->cfg->prov_disc_fail) p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_REJECTED); p2p_parse_free(&msg); goto out; } report_config_methods = dev->req_config_methods; dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD); if (dev->req_config_methods & WPS_CONFIG_DISPLAY) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR " accepted to show a PIN on display", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_DISPLAY; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR " accepted to write our PIN using keypad", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_KEYPAD; } /* Store the provisioning info */ dev->wps_prov_info = msg.wps_config_methods; p2p_parse_free(&msg); out: dev->req_config_methods = 0; p2p->cfg->send_action_done(p2p->cfg->cb_ctx); if (p2p->cfg->prov_disc_resp) p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa, report_config_methods); }
void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_message msg; struct p2p_device *go; u8 status; wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Received Device Discoverability Response from " MACSTR, MAC2STR(sa)); go = p2p->pending_client_disc_go; if (go == NULL || os_memcmp(sa, go->info.p2p_device_addr, ETH_ALEN) != 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore unexpected " "Device Discoverability Response"); return; } if (p2p_parse(data, len, &msg)) return; if (msg.status == NULL) { p2p_parse_free(&msg); return; } if (msg.dialog_token != go->dialog_token) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore Device " "Discoverability Response with unexpected dialog " "token %u (expected %u)", msg.dialog_token, go->dialog_token); p2p_parse_free(&msg); return; } status = *msg.status; p2p_parse_free(&msg); wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Device Discoverability Response status %u", status); if (p2p->go_neg_peer == NULL || os_memcmp(p2p->pending_client_disc_addr, p2p->go_neg_peer->info.p2p_device_addr, ETH_ALEN) != 0 || os_memcmp(p2p->go_neg_peer->member_in_go_dev, go->info.p2p_device_addr, ETH_ALEN) != 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending " "operation with the client discoverability peer " "anymore"); return; } if (status == 0) { /* * Peer is expected to be awake for at least 100 TU; try to * connect immediately. */ wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Client discoverability request succeeded"); if (p2p->state == P2P_CONNECT) { /* * Change state to force the timeout to start in * P2P_CONNECT again without going through the short * Listen state. */ p2p_set_state(p2p, P2P_CONNECT_LISTEN); p2p->cfg->send_action_done(p2p->cfg->cb_ctx); } p2p_set_timeout(p2p, 0, 0); } else { /* * Client discoverability request failed; try to connect from * timeout. */ wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Client discoverability request failed"); p2p_set_timeout(p2p, 0, 500000); } }
void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_message msg; struct p2p_device *dev; u16 report_config_methods = 0, req_config_methods; u8 status = P2P_SC_SUCCESS; int success = 0; u32 adv_id = 0; u8 conncap = P2PS_SETUP_NEW; u8 adv_mac[ETH_ALEN]; u8 group_mac[ETH_ALEN]; int passwd_id = DEV_PW_DEFAULT; if (p2p_parse(data, len, &msg)) { return; } /* Parse the P2PS members present */ if (msg.status) { status = *msg.status; } if (msg.intended_addr) { os_memcpy(group_mac, msg.intended_addr, ETH_ALEN); } else { os_memset(group_mac, 0, ETH_ALEN); } if (msg.adv_mac) { os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN); } else { os_memset(adv_mac, 0, ETH_ALEN); } if (msg.adv_id) { adv_id = WPA_GET_LE32(msg.adv_id); } if (msg.conn_cap) { conncap = *msg.conn_cap; /* Switch bits to local relative */ switch (conncap) { case P2PS_SETUP_GROUP_OWNER: conncap = P2PS_SETUP_CLIENT; break; case P2PS_SETUP_CLIENT: conncap = P2PS_SETUP_GROUP_OWNER; break; } } p2p_dbg(p2p, "Received Provision Discovery Response from " MACSTR " with config methods 0x%x", MAC2STR(sa), msg.wps_config_methods); dev = p2p_get_device(p2p, sa); if (dev == NULL || !dev->req_config_methods) { p2p_dbg(p2p, "Ignore Provision Discovery Response from " MACSTR " with no pending request", MAC2STR(sa)); p2p_parse_free(&msg); return; } if (dev->dialog_token != msg.dialog_token) { p2p_dbg(p2p, "Ignore Provision Discovery Response with unexpected Dialog Token %u (expected %u)", msg.dialog_token, dev->dialog_token); p2p_parse_free(&msg); return; } if (p2p->pending_action_state == P2P_PENDING_PD) { os_memset(p2p->pending_pd_devaddr, 0, ETH_ALEN); p2p->pending_action_state = P2P_NO_PENDING_ACTION; } /* * Use a local copy of the requested config methods since * p2p_reset_pending_pd() can clear this in the peer entry. */ req_config_methods = dev->req_config_methods; /* * If the response is from the peer to whom a user initiated request * was sent earlier, we reset that state info here. */ if (p2p->user_initiated_pd && os_memcmp(p2p->pending_pd_devaddr, sa, ETH_ALEN) == 0) { p2p_reset_pending_pd(p2p); } if (msg.wps_config_methods != req_config_methods) { p2p_dbg(p2p, "Peer rejected our Provision Discovery Request (received config_methods 0x%x expected 0x%x", msg.wps_config_methods, req_config_methods); if (p2p->cfg->prov_disc_fail) { p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_REJECTED, adv_id, adv_mac, NULL); } p2p_parse_free(&msg); p2ps_prov_free(p2p); goto out; } report_config_methods = req_config_methods; dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD | P2P_DEV_PD_PEER_P2PS); if (req_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " accepted to show a PIN on display", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_DISPLAY; passwd_id = DEV_PW_REGISTRAR_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " accepted to write our PIN using keypad", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_KEYPAD; passwd_id = DEV_PW_USER_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) { p2p_dbg(p2p, "Peer " MACSTR " accepted P2PS PIN", MAC2STR(sa)); dev->flags |= P2P_DEV_PD_PEER_P2PS; passwd_id = DEV_PW_P2PS_DEFAULT; } if ((msg.conn_cap || msg.persistent_dev) && msg.adv_id && (status == P2P_SC_SUCCESS || status == P2P_SC_SUCCESS_DEFERRED) && p2p->p2ps_prov) { if (p2p->cfg->p2ps_prov_complete) { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, status, sa, adv_mac, p2p->p2ps_prov->session_mac, group_mac, adv_id, p2p->p2ps_prov->session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 1, 0, NULL); } p2ps_prov_free(p2p); } if (status != P2P_SC_SUCCESS && status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && status != P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { if (p2p->cfg->p2ps_prov_complete) { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, status, sa, adv_mac, p2p->p2ps_prov->session_mac, group_mac, adv_id, p2p->p2ps_prov->session_id, 0, 0, NULL, 0, 1, 0, NULL); } p2ps_prov_free(p2p); } if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { if (p2p->cfg->remove_stale_groups) { p2p->cfg->remove_stale_groups(p2p->cfg->cb_ctx, dev->info.p2p_device_addr, NULL, NULL, 0); } if (msg.session_info && msg.session_info_len) { size_t info_len = msg.session_info_len; char *deferred_sess_resp = os_malloc(2 * info_len + 1); if (!deferred_sess_resp) { p2p_parse_free(&msg); p2ps_prov_free(p2p); goto out; } utf8_escape((char *)msg.session_info, info_len, deferred_sess_resp, 2 * info_len + 1); if (p2p->cfg->prov_disc_fail) { p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_INFO_UNAVAILABLE, adv_id, adv_mac, deferred_sess_resp); } os_free(deferred_sess_resp); } else if (p2p->cfg->prov_disc_fail) { p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_INFO_UNAVAILABLE, adv_id, adv_mac, NULL); } } else if (msg.wps_config_methods != dev->req_config_methods || status != P2P_SC_SUCCESS) { p2p_dbg(p2p, "Peer rejected our Provision Discovery Request"); if (p2p->cfg->prov_disc_fail) { p2p->cfg->prov_disc_fail(p2p->cfg->cb_ctx, sa, P2P_PROV_DISC_REJECTED, 0, NULL, NULL); } p2p_parse_free(&msg); p2ps_prov_free(p2p); goto out; } /* Store the provisioning info */ dev->wps_prov_info = msg.wps_config_methods; p2p_parse_free(&msg); success = 1; out: dev->req_config_methods = 0; p2p->cfg->send_action_done(p2p->cfg->cb_ctx); if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) { p2p_dbg(p2p, "Start GO Neg after the PD-before-GO-Neg workaround with " MACSTR, MAC2STR(dev->info.p2p_device_addr)); dev->flags &= ~P2P_DEV_PD_BEFORE_GO_NEG; p2p_connect_send(p2p, dev); return; } if (success && p2p->cfg->prov_disc_resp) { p2p->cfg->prov_disc_resp(p2p->cfg->cb_ctx, sa, report_config_methods); } if (p2p->state == P2P_PD_DURING_FIND) { p2p_clear_timeout(p2p); p2p_continue_find(p2p); } }
void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_message msg; struct p2p_device *dev; int freq; enum p2p_status_code reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; struct wpabuf *resp; u32 adv_id = 0; struct p2ps_advertisement *p2ps_adv = NULL; u8 conncap = P2PS_SETUP_NEW; u8 auto_accept = 0; u32 session_id = 0; u8 session_mac[ETH_ALEN]; u8 adv_mac[ETH_ALEN]; u8 group_mac[ETH_ALEN]; int passwd_id = DEV_PW_DEFAULT; u16 config_methods; if (p2p_parse(data, len, &msg)) { return; } p2p_dbg(p2p, "Received Provision Discovery Request from " MACSTR " with config methods 0x%x (freq=%d)", MAC2STR(sa), msg.wps_config_methods, rx_freq); dev = p2p_get_device(p2p, sa); if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { p2p_dbg(p2p, "Provision Discovery Request from unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, 0)) { p2p_dbg(p2p, "Provision Discovery Request add device failed " MACSTR, MAC2STR(sa)); } } else if (msg.wfd_subelems) { wpabuf_free(dev->info.wfd_subelems); dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems); } if (!(msg.wps_config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_PUSHBUTTON | WPS_CONFIG_P2PS))) { p2p_dbg(p2p, "Unsupported Config Methods in Provision Discovery Request"); goto out; } /* Legacy (non-P2PS) - Unknown groups allowed for P2PS */ if (!msg.adv_id && msg.group_id) { size_t i; for (i = 0; i < p2p->num_groups; i++) { if (p2p_group_is_group_id_match(p2p->groups[i], msg.group_id, msg.group_id_len)) { break; } } if (i == p2p->num_groups) { p2p_dbg(p2p, "PD request for unknown P2P Group ID - reject"); goto out; } } if (dev) { dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD | P2P_DEV_PD_PEER_P2PS); /* Remove stale persistent groups */ if (p2p->cfg->remove_stale_groups) { p2p->cfg->remove_stale_groups(p2p->cfg->cb_ctx, dev->info.p2p_device_addr, msg.persistent_dev, msg.persistent_ssid, msg.persistent_ssid_len); } } if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " requested us to show a PIN on display", MAC2STR(sa)); if (dev) { dev->flags |= P2P_DEV_PD_PEER_KEYPAD; } passwd_id = DEV_PW_USER_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " requested us to write its PIN using keypad", MAC2STR(sa)); if (dev) { dev->flags |= P2P_DEV_PD_PEER_DISPLAY; } passwd_id = DEV_PW_REGISTRAR_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) { p2p_dbg(p2p, "Peer " MACSTR " requesting P2PS PIN", MAC2STR(sa)); if (dev) { dev->flags |= P2P_DEV_PD_PEER_P2PS; } passwd_id = DEV_PW_P2PS_DEFAULT; } reject = P2P_SC_SUCCESS; os_memset(session_mac, 0, ETH_ALEN); os_memset(adv_mac, 0, ETH_ALEN); os_memset(group_mac, 0, ETH_ALEN); if (msg.adv_id && msg.session_id && msg.session_mac && msg.adv_mac && (msg.status || msg.conn_cap)) { u8 remote_conncap; if (msg.intended_addr) { os_memcpy(group_mac, msg.intended_addr, ETH_ALEN); } os_memcpy(session_mac, msg.session_mac, ETH_ALEN); os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN); session_id = WPA_GET_LE32(msg.session_id); adv_id = WPA_GET_LE32(msg.adv_id); if (!msg.status) { p2ps_adv = p2p_service_p2ps_id(p2p, adv_id); } p2p_dbg(p2p, "adv_id: %x - p2ps_adv - %p", adv_id, p2ps_adv); if (msg.conn_cap) { conncap = *msg.conn_cap; } remote_conncap = conncap; if (p2ps_adv) { auto_accept = p2ps_adv->auto_accept; conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx, conncap, auto_accept); p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d", auto_accept, remote_conncap, conncap); if (p2ps_adv->config_methods && !(msg.wps_config_methods & p2ps_adv->config_methods)) { p2p_dbg(p2p, "Unsupported config methods in Provision Discovery Request (own=0x%x peer=0x%x)", p2ps_adv->config_methods, msg.wps_config_methods); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (!p2ps_adv->state) { p2p_dbg(p2p, "P2PS state unavailable"); reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; } else if (!conncap) { p2p_dbg(p2p, "Conncap resolution failed"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Keypad - always defer"); auto_accept = 0; } if (auto_accept || reject != P2P_SC_SUCCESS) { struct p2ps_provision *tmp; if (reject == P2P_SC_SUCCESS && !conncap) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id, msg.wps_config_methods, session_mac, adv_mac) < 0) { reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; goto out; } tmp = p2p->p2ps_prov; if (conncap) { tmp->conncap = conncap; tmp->status = P2P_SC_SUCCESS; } else { tmp->conncap = auto_accept; tmp->status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (reject != P2P_SC_SUCCESS) { goto out; } } } else if (!msg.status) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } if (!msg.status && !auto_accept && (!p2p->p2ps_prov || p2p->p2ps_prov->adv_id != adv_id)) { struct p2ps_provision *tmp; if (!conncap) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id, msg.wps_config_methods, session_mac, adv_mac) < 0) { reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; goto out; } tmp = p2p->p2ps_prov; reject = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; tmp->status = reject; } if (msg.status) { if (*msg.status && *msg.status != P2P_SC_SUCCESS_DEFERRED) { reject = *msg.status; } else if (*msg.status == P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { u16 method = p2p->p2ps_prov->method; conncap = p2p->cfg->p2ps_group_capability(p2p->cfg->cb_ctx, remote_conncap, p2p->p2ps_prov->conncap); p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d", p2p->p2ps_prov->conncap, remote_conncap, conncap); /* * Ensure that if we asked for PIN originally, * our method is consistent with original * request. */ if (method & WPS_CONFIG_DISPLAY) { method = WPS_CONFIG_KEYPAD; } else if (method & WPS_CONFIG_KEYPAD) { method = WPS_CONFIG_DISPLAY; } /* Reject this "Deferred Accept* if incompatible * conncap or method */ if (!conncap || !(msg.wps_config_methods & method)) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else { reject = P2P_SC_SUCCESS; } p2p->p2ps_prov->status = reject; p2p->p2ps_prov->conncap = conncap; } } } out: if (reject == P2P_SC_SUCCESS || reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { config_methods = msg.wps_config_methods; } else { config_methods = 0; } resp = p2p_build_prov_disc_resp(p2p, dev, msg.dialog_token, reject, config_methods, adv_id, msg.group_id, msg.group_id_len, msg.persistent_ssid, msg.persistent_ssid_len); if (resp == NULL) { p2p_parse_free(&msg); return; } p2p_dbg(p2p, "Sending Provision Discovery Response"); if (rx_freq > 0) { freq = rx_freq; } else { freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); } if (freq < 0) { p2p_dbg(p2p, "Unknown regulatory class/channel"); wpabuf_free(resp); p2p_parse_free(&msg); return; } p2p->pending_action_state = P2P_PENDING_PD_RESPONSE; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { p2p_dbg(p2p, "Failed to send Action frame"); } else { p2p->send_action_in_progress = 1; } wpabuf_free(resp); if (!p2p->cfg->p2ps_prov_complete) { /* Don't emit anything */ } else if (msg.status && *msg.status != P2P_SC_SUCCESS && *msg.status != P2P_SC_SUCCESS_DEFERRED) { reject = *msg.status; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject, sa, adv_mac, session_mac, NULL, adv_id, session_id, 0, 0, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL); } else if (msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { p2p->p2ps_prov->status = reject; p2p->p2ps_prov->conncap = conncap; if (reject != P2P_SC_SUCCESS) { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject, sa, adv_mac, session_mac, NULL, adv_id, session_id, conncap, 0, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL); } else { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL); } } else if (msg.status && p2p->p2ps_prov) { p2p->p2ps_prov->status = P2P_SC_SUCCESS; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL); } else if (msg.status) { } else if (auto_accept && reject == P2P_SC_SUCCESS) { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL); } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && (!msg.session_info || !msg.session_info_len)) { p2p->p2ps_prov->method = msg.wps_config_methods; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 1, NULL); } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { size_t buf_len = msg.session_info_len; char *buf = os_malloc(2 * buf_len + 1); if (buf) { p2p->p2ps_prov->method = msg.wps_config_methods; utf8_escape((char *)msg.session_info, buf_len, buf, 2 * buf_len + 1); p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 1, buf); os_free(buf); } } if (reject == P2P_SC_SUCCESS && p2p->cfg->prov_disc_req) { const u8 *dev_addr = sa; if (msg.p2p_device_addr) { dev_addr = msg.p2p_device_addr; } p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa, msg.wps_config_methods, dev_addr, msg.pri_dev_type, msg.device_name, msg.config_methods, msg.capability ? msg.capability[0] : 0, msg.capability ? msg.capability[1] : 0, msg.group_id, msg.group_id_len); } p2p_parse_free(&msg); }
void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_message msg; struct p2p_device *dev; int freq; enum p2p_status_code reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; struct wpabuf *resp; u32 adv_id = 0; struct p2ps_advertisement *p2ps_adv = NULL; u8 conncap = P2PS_SETUP_NEW; u8 auto_accept = 0; u32 session_id = 0; u8 session_mac[ETH_ALEN]; u8 adv_mac[ETH_ALEN]; const u8 *group_mac; int passwd_id = DEV_PW_DEFAULT; u16 config_methods; u16 allowed_config_methods = WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD; struct p2ps_feature_capab resp_fcap = { 0, 0 }; struct p2ps_feature_capab *req_fcap; if (p2p_parse(data, len, &msg)) return; p2p_dbg(p2p, "Received Provision Discovery Request from " MACSTR " with config methods 0x%x (freq=%d)", MAC2STR(sa), msg.wps_config_methods, rx_freq); group_mac = msg.intended_addr; dev = p2p_get_device(p2p, sa); if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { p2p_dbg(p2p, "Provision Discovery Request from unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, 0)) { p2p_dbg(p2p, "Provision Discovery Request add device failed " MACSTR, MAC2STR(sa)); } } else if (msg.wfd_subelems) { wpabuf_free(dev->info.wfd_subelems); dev->info.wfd_subelems = wpabuf_dup(msg.wfd_subelems); } if (msg.adv_id) allowed_config_methods |= WPS_CONFIG_P2PS; else allowed_config_methods |= WPS_CONFIG_PUSHBUTTON; if (!(msg.wps_config_methods & allowed_config_methods)) { p2p_dbg(p2p, "Unsupported Config Methods in Provision Discovery Request"); goto out; } /* Legacy (non-P2PS) - Unknown groups allowed for P2PS */ if (!msg.adv_id && msg.group_id) { size_t i; for (i = 0; i < p2p->num_groups; i++) { if (p2p_group_is_group_id_match(p2p->groups[i], msg.group_id, msg.group_id_len)) break; } if (i == p2p->num_groups) { p2p_dbg(p2p, "PD request for unknown P2P Group ID - reject"); goto out; } } if (dev) { dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD | P2P_DEV_PD_PEER_P2PS); /* Remove stale persistent groups */ if (p2p->cfg->remove_stale_groups) { p2p->cfg->remove_stale_groups( p2p->cfg->cb_ctx, dev->info.p2p_device_addr, msg.persistent_dev, msg.persistent_ssid, msg.persistent_ssid_len); } } if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) { p2p_dbg(p2p, "Peer " MACSTR " requested us to show a PIN on display", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_KEYPAD; passwd_id = DEV_PW_USER_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Peer " MACSTR " requested us to write its PIN using keypad", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_DISPLAY; passwd_id = DEV_PW_REGISTRAR_SPECIFIED; } else if (msg.wps_config_methods & WPS_CONFIG_P2PS) { p2p_dbg(p2p, "Peer " MACSTR " requesting P2PS PIN", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_P2PS; passwd_id = DEV_PW_P2PS_DEFAULT; } reject = P2P_SC_SUCCESS; os_memset(session_mac, 0, ETH_ALEN); os_memset(adv_mac, 0, ETH_ALEN); /* Note 1: A feature capability attribute structure can be changed * in the future. The assumption is that such modifications are * backwards compatible, therefore we allow processing of * msg.feature_cap exceeding the size of the p2ps_feature_capab * structure. * Note 2: Vverification of msg.feature_cap_len below has to be changed * to allow 2 byte feature capability processing if struct * p2ps_feature_capab is extended to include additional fields and it * affects the structure size. */ if (msg.adv_id && msg.session_id && msg.session_mac && msg.adv_mac && msg.feature_cap && msg.feature_cap_len >= sizeof(*req_fcap) && (msg.status || msg.conn_cap)) { u8 remote_conncap; req_fcap = (struct p2ps_feature_capab *) msg.feature_cap; os_memcpy(session_mac, msg.session_mac, ETH_ALEN); os_memcpy(adv_mac, msg.adv_mac, ETH_ALEN); session_id = WPA_GET_LE32(msg.session_id); adv_id = WPA_GET_LE32(msg.adv_id); if (!msg.status) p2ps_adv = p2p_service_p2ps_id(p2p, adv_id); p2p_dbg(p2p, "adv_id: %x - p2ps_adv - %p", adv_id, p2ps_adv); if (msg.conn_cap) conncap = *msg.conn_cap; remote_conncap = conncap; if (p2ps_adv) { auto_accept = p2ps_adv->auto_accept; conncap = p2p->cfg->p2ps_group_capability( p2p->cfg->cb_ctx, conncap, auto_accept); p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d", auto_accept, remote_conncap, conncap); resp_fcap.cpt = p2ps_own_preferred_cpt(p2ps_adv->cpt_priority, req_fcap->cpt); p2p_dbg(p2p, "cpt: service:0x%x remote:0x%x result:0x%x", p2ps_adv->cpt_mask, req_fcap->cpt, resp_fcap.cpt); if (!resp_fcap.cpt) { p2p_dbg(p2p, "Incompatible P2PS feature capability CPT bitmask"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (p2ps_adv->config_methods && !(msg.wps_config_methods & p2ps_adv->config_methods)) { p2p_dbg(p2p, "Unsupported config methods in Provision Discovery Request (own=0x%x peer=0x%x)", p2ps_adv->config_methods, msg.wps_config_methods); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (!p2ps_adv->state) { p2p_dbg(p2p, "P2PS state unavailable"); reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; } else if (!conncap) { p2p_dbg(p2p, "Conncap resolution failed"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { p2p_dbg(p2p, "Keypad - always defer"); auto_accept = 0; } if (auto_accept || reject != P2P_SC_SUCCESS) { struct p2ps_provision *tmp; if (reject == P2P_SC_SUCCESS && !conncap) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (p2ps_setup_p2ps_prov( p2p, adv_id, session_id, msg.wps_config_methods, session_mac, adv_mac) < 0) { reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; goto out; } tmp = p2p->p2ps_prov; if (conncap) { tmp->conncap = conncap; tmp->status = P2P_SC_SUCCESS; } else { tmp->conncap = auto_accept; tmp->status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } if (reject != P2P_SC_SUCCESS) goto out; } } else if (!msg.status) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } if (!msg.status && !auto_accept && (!p2p->p2ps_prov || p2p->p2ps_prov->adv_id != adv_id)) { struct p2ps_provision *tmp; if (!conncap) { reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; goto out; } if (p2ps_setup_p2ps_prov(p2p, adv_id, session_id, msg.wps_config_methods, session_mac, adv_mac) < 0) { reject = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE; goto out; } tmp = p2p->p2ps_prov; reject = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; tmp->status = reject; } if (msg.status) { if (*msg.status && *msg.status != P2P_SC_SUCCESS_DEFERRED) { reject = *msg.status; } else if (*msg.status == P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { u16 method = p2p->p2ps_prov->method; conncap = p2p->cfg->p2ps_group_capability( p2p->cfg->cb_ctx, remote_conncap, p2p->p2ps_prov->conncap); p2p_dbg(p2p, "Conncap: local:%d remote:%d result:%d", p2p->p2ps_prov->conncap, remote_conncap, conncap); resp_fcap.cpt = p2ps_own_preferred_cpt( p2p->p2ps_prov->cpt_priority, req_fcap->cpt); p2p_dbg(p2p, "cpt: local:0x%x remote:0x%x result:0x%x", p2p->p2ps_prov->cpt_mask, req_fcap->cpt, resp_fcap.cpt); /* * Ensure that if we asked for PIN originally, * our method is consistent with original * request. */ if (method & WPS_CONFIG_DISPLAY) method = WPS_CONFIG_KEYPAD; else if (method & WPS_CONFIG_KEYPAD) method = WPS_CONFIG_DISPLAY; if (!conncap || !(msg.wps_config_methods & method)) { /* * Reject this "Deferred Accept* * if incompatible conncap or method */ reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else if (!resp_fcap.cpt) { p2p_dbg(p2p, "Incompatible P2PS feature capability CPT bitmask"); reject = P2P_SC_FAIL_INCOMPATIBLE_PARAMS; } else { reject = P2P_SC_SUCCESS; } p2p->p2ps_prov->status = reject; p2p->p2ps_prov->conncap = conncap; } } } out: if (reject == P2P_SC_SUCCESS || reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) config_methods = msg.wps_config_methods; else config_methods = 0; resp = p2p_build_prov_disc_resp(p2p, dev, msg.dialog_token, reject, config_methods, adv_id, msg.group_id, msg.group_id_len, msg.persistent_ssid, msg.persistent_ssid_len, (const u8 *) &resp_fcap, sizeof(resp_fcap)); if (resp == NULL) { p2p_parse_free(&msg); return; } p2p_dbg(p2p, "Sending Provision Discovery Response"); if (rx_freq > 0) freq = rx_freq; else freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); if (freq < 0) { p2p_dbg(p2p, "Unknown regulatory class/channel"); wpabuf_free(resp); p2p_parse_free(&msg); return; } p2p->pending_action_state = P2P_PENDING_PD_RESPONSE; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { p2p_dbg(p2p, "Failed to send Action frame"); } else p2p->send_action_in_progress = 1; wpabuf_free(resp); if (!p2p->cfg->p2ps_prov_complete) { /* Don't emit anything */ } else if (msg.status && *msg.status != P2P_SC_SUCCESS && *msg.status != P2P_SC_SUCCESS_DEFERRED) { reject = *msg.status; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject, sa, adv_mac, session_mac, NULL, adv_id, session_id, 0, 0, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, NULL, 0); } else if (msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED && p2p->p2ps_prov) { p2p->p2ps_prov->status = reject; p2p->p2ps_prov->conncap = conncap; if (reject != P2P_SC_SUCCESS) p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, reject, sa, adv_mac, session_mac, NULL, adv_id, session_id, conncap, 0, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, NULL, 0); else p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap)); } else if (msg.status && p2p->p2ps_prov) { p2p->p2ps_prov->status = P2P_SC_SUCCESS; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, *msg.status, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap)); } else if (msg.status) { } else if (auto_accept && reject == P2P_SC_SUCCESS) { p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 0, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap)); } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && (!msg.session_info || !msg.session_info_len)) { p2p->p2ps_prov->method = msg.wps_config_methods; p2p->cfg->p2ps_prov_complete(p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 1, NULL, (const u8 *) &resp_fcap, sizeof(resp_fcap)); } else if (reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) { size_t buf_len = msg.session_info_len; char *buf = os_malloc(2 * buf_len + 1); if (buf) { p2p->p2ps_prov->method = msg.wps_config_methods; utf8_escape((char *) msg.session_info, buf_len, buf, 2 * buf_len + 1); p2p->cfg->p2ps_prov_complete( p2p->cfg->cb_ctx, P2P_SC_SUCCESS, sa, adv_mac, session_mac, group_mac, adv_id, session_id, conncap, passwd_id, msg.persistent_ssid, msg.persistent_ssid_len, 0, 1, buf, (const u8 *) &resp_fcap, sizeof(resp_fcap)); os_free(buf); } } /* * prov_disc_req callback is used to generate P2P-PROV-DISC-ENTER-PIN, * P2P-PROV-DISC-SHOW-PIN, and P2P-PROV-DISC-PBC-REQ events. * Call it either on legacy P2P PD or on P2PS PD only if we need to * enter/show PIN. * * The callback is called in the following cases: * 1. Legacy P2P PD request, response status SUCCESS * 2. P2PS advertiser, method: DISPLAY, autoaccept: TRUE, * response status: SUCCESS * 3. P2PS advertiser, method DISPLAY, autoaccept: FALSE, * response status: INFO_CURRENTLY_UNAVAILABLE * 4. P2PS advertiser, method: KEYPAD, autoaccept==any, * response status: INFO_CURRENTLY_UNAVAILABLE * 5. P2PS follow-on with SUCCESS_DEFERRED, * advertiser role: DISPLAY, autoaccept: FALSE, * seeker: KEYPAD, response status: SUCCESS */ if (p2p->cfg->prov_disc_req && ((reject == P2P_SC_SUCCESS && !msg.adv_id) || (!msg.status && (reject == P2P_SC_SUCCESS || reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) && passwd_id == DEV_PW_USER_SPECIFIED) || (!msg.status && reject == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE && passwd_id == DEV_PW_REGISTRAR_SPECIFIED) || (reject == P2P_SC_SUCCESS && msg.status && *msg.status == P2P_SC_SUCCESS_DEFERRED && passwd_id == DEV_PW_REGISTRAR_SPECIFIED))) { const u8 *dev_addr = sa; if (msg.p2p_device_addr) dev_addr = msg.p2p_device_addr; p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa, msg.wps_config_methods, dev_addr, msg.pri_dev_type, msg.device_name, msg.config_methods, msg.capability ? msg.capability[0] : 0, msg.capability ? msg.capability[1] : 0, msg.group_id, msg.group_id_len); } if (dev && reject == P2P_SC_SUCCESS) { switch (config_methods) { case WPS_CONFIG_DISPLAY: dev->wps_prov_info = WPS_CONFIG_KEYPAD; break; case WPS_CONFIG_KEYPAD: dev->wps_prov_info = WPS_CONFIG_DISPLAY; break; case WPS_CONFIG_PUSHBUTTON: dev->wps_prov_info = WPS_CONFIG_PUSHBUTTON; break; case WPS_CONFIG_P2PS: dev->wps_prov_info = WPS_CONFIG_P2PS; break; default: dev->wps_prov_info = 0; break; } if (msg.intended_addr) os_memcpy(dev->interface_addr, msg.intended_addr, ETH_ALEN); } p2p_parse_free(&msg); }
void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_device *dev; struct p2p_message msg; struct wpabuf *resp = NULL; u8 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; int freq; int go = 0; u8 group_bssid[ETH_ALEN], *bssid; int op_freq = 0; u8 reg_class = 0, channel = 0; struct p2p_channels intersection, *channels = NULL; int persistent; os_memset(group_bssid, 0, sizeof(group_bssid)); wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Received Invitation Request from " MACSTR " (freq=%d)", MAC2STR(sa), rx_freq); if (p2p_parse(data, len, &msg)) return; dev = p2p_get_device(p2p, sa); if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Invitation Request from unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, 0, 0, data + 1, len - 1, 0)) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Invitation Request add device failed " MACSTR, MAC2STR(sa)); status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; goto fail; } dev = p2p_get_device(p2p, sa); if (dev == NULL) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Reject Invitation Request from unknown " "peer " MACSTR, MAC2STR(sa)); status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; goto fail; } } if (!msg.group_id || !msg.channel_list) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Mandatory attribute missing in Invitation " "Request from " MACSTR, MAC2STR(sa)); status = P2P_SC_FAIL_INVALID_PARAMS; goto fail; } if (msg.invitation_flags) persistent = *msg.invitation_flags & P2P_INVITATION_FLAGS_TYPE; else { /* Invitation Flags is a mandatory attribute starting from P2P * spec 1.06. As a backwards compatibility mechanism, assume * the request was for a persistent group if the attribute is * missing. */ wpa_printf(MSG_DEBUG, "P2P: Mandatory Invitation Flags " "attribute missing from Invitation Request"); persistent = 1; } if (p2p_peer_channels_check(p2p, &p2p->cfg->channels, dev, msg.channel_list, msg.channel_list_len) < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No common channels found"); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } if (p2p->cfg->invitation_process) { status = p2p->cfg->invitation_process( p2p->cfg->cb_ctx, sa, msg.group_bssid, msg.group_id, msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN, &go, group_bssid, &op_freq, persistent); } if (op_freq) { if (p2p_freq_to_channel(p2p->cfg->country, op_freq, ®_class, &channel) < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unknown forced freq %d MHz from " "invitation_process()", op_freq); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } p2p_channels_intersect(&p2p->cfg->channels, &dev->channels, &intersection); if (!p2p_channels_includes(&intersection, reg_class, channel)) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: forced freq %d MHz not in the supported " "channels interaction", op_freq); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } if (status == P2P_SC_SUCCESS) channels = &intersection; } else { op_freq = p2p_channel_to_freq(p2p->cfg->country, p2p->cfg->op_reg_class, p2p->cfg->op_channel); if (op_freq < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unknown operational channel " "(country=%c%c reg_class=%u channel=%u)", p2p->cfg->country[0], p2p->cfg->country[1], p2p->cfg->op_reg_class, p2p->cfg->op_channel); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } p2p_channels_intersect(&p2p->cfg->channels, &dev->channels, &intersection); if (status == P2P_SC_SUCCESS) { reg_class = p2p->cfg->op_reg_class; channel = p2p->cfg->op_channel; channels = &intersection; } } fail: if (go && status == P2P_SC_SUCCESS && !is_zero_ether_addr(group_bssid)) bssid = group_bssid; else bssid = NULL; resp = p2p_build_invitation_resp(p2p, dev, msg.dialog_token, status, bssid, reg_class, channel, channels); if (resp == NULL) goto out; if (rx_freq > 0) freq = rx_freq; else freq = p2p_channel_to_freq(p2p->cfg->country, p2p->cfg->reg_class, p2p->cfg->channel); if (freq < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unknown regulatory class/channel"); goto out; } /* * Store copy of invitation data to be used when processing TX status * callback for the Acton frame. */ os_memcpy(p2p->inv_sa, sa, ETH_ALEN); if (msg.group_bssid) { os_memcpy(p2p->inv_group_bssid, msg.group_bssid, ETH_ALEN); p2p->inv_group_bssid_ptr = p2p->inv_group_bssid; } else p2p->inv_group_bssid_ptr = NULL; if (msg.group_id_len - ETH_ALEN <= 32) { os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN); p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN; } os_memcpy(p2p->inv_go_dev_addr, msg.group_id, ETH_ALEN); p2p->inv_status = status; p2p->inv_op_freq = op_freq; p2p->pending_action_state = P2P_PENDING_INVITATION_RESPONSE; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Failed to send Action frame"); } out: wpabuf_free(resp); p2p_parse_free(&msg); }
void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_device *dev; struct p2p_message msg; struct p2p_channels intersection, *channels = NULL; p2p_dbg(p2p, "Received Invitation Response from " MACSTR, MAC2STR(sa)); dev = p2p_get_device(p2p, sa); if (dev == NULL) { p2p_dbg(p2p, "Ignore Invitation Response from unknown peer " MACSTR, MAC2STR(sa)); p2p->cfg->send_action_done(p2p->cfg->cb_ctx); return; } if (dev != p2p->invite_peer) { p2p_dbg(p2p, "Ignore unexpected Invitation Response from peer " MACSTR, MAC2STR(sa)); p2p->cfg->send_action_done(p2p->cfg->cb_ctx); return; } if (p2p_parse(data, len, &msg)) { p2p->cfg->send_action_done(p2p->cfg->cb_ctx); return; } if (!msg.status) { p2p_dbg(p2p, "Mandatory Status attribute missing in Invitation Response from " MACSTR, MAC2STR(sa)); p2p_parse_free(&msg); p2p->cfg->send_action_done(p2p->cfg->cb_ctx); return; } /* * We should not really receive a replayed response twice since * duplicate frames are supposed to be dropped. However, not all drivers * do that for pre-association frames. We did not use to verify dialog * token matches for invitation response frames, but that check can be * safely used to drop a replayed response to the previous Invitation * Request in case the suggested operating channel was changed. This * allows a duplicated reject frame to be dropped with the assumption * that the real response follows after it. */ if (*msg.status == P2P_SC_FAIL_NO_COMMON_CHANNELS && p2p->retry_invite_req_sent && msg.dialog_token != dev->dialog_token) { p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)", msg.dialog_token, dev->dialog_token); p2p_parse_free(&msg); return; } if (*msg.status == P2P_SC_FAIL_NO_COMMON_CHANNELS && p2p->retry_invite_req && p2p_channel_random_social(&p2p->cfg->channels, &p2p->op_reg_class, &p2p->op_channel, NULL, NULL) == 0) { p2p->retry_invite_req = 0; p2p->cfg->send_action_done(p2p->cfg->cb_ctx); p2p->cfg->stop_listen(p2p->cfg->cb_ctx); p2p_set_state(p2p, P2P_INVITE); p2p_dbg(p2p, "Resend Invitation Request setting op_class %u channel %u as operating channel", p2p->op_reg_class, p2p->op_channel); p2p->retry_invite_req_sent = 1; p2p_invite_send(p2p, p2p->invite_peer, p2p->invite_go_dev_addr, p2p->invite_dev_pw_id); p2p_parse_free(&msg); return; } p2p->cfg->send_action_done(p2p->cfg->cb_ctx); p2p->retry_invite_req = 0; if (!msg.channel_list && *msg.status == P2P_SC_SUCCESS) { p2p_dbg(p2p, "Mandatory Channel List attribute missing in Invitation Response from " MACSTR, MAC2STR(sa)); #ifdef CONFIG_P2P_STRICT p2p_parse_free(&msg); return; #endif /* CONFIG_P2P_STRICT */ /* Try to survive without peer channel list */ channels = &p2p->channels; } else if (!msg.channel_list) { /* Non-success cases are not required to include Channel List */ channels = &p2p->channels; } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev, msg.channel_list, msg.channel_list_len) < 0) { p2p_dbg(p2p, "No common channels found"); p2p_parse_free(&msg); return; } else { p2p_channels_intersect(&p2p->channels, &dev->channels, &intersection); channels = &intersection; } if (p2p->cfg->invitation_result) { int peer_oper_freq = 0; int freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel); if (freq < 0) freq = 0; if (msg.operating_channel) { peer_oper_freq = p2p_channel_to_freq( msg.operating_channel[3], msg.operating_channel[4]); if (peer_oper_freq < 0) peer_oper_freq = 0; } /* * Use the driver preferred frequency list extension if * supported. */ p2p_check_pref_chan(p2p, 0, dev, &msg); p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status, msg.group_bssid, channels, sa, freq, peer_oper_freq); } p2p_parse_free(&msg); p2p_clear_timeout(p2p); p2p_set_state(p2p, P2P_IDLE); p2p->invite_peer = NULL; }
void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_device *dev; struct p2p_message msg; struct wpabuf *resp = NULL; u8 status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; int freq; int go = 0; u8 group_bssid[ETH_ALEN], *bssid; int op_freq = 0; u8 reg_class = 0, channel = 0; struct p2p_channels all_channels, intersection, *channels = NULL; int persistent; os_memset(group_bssid, 0, sizeof(group_bssid)); p2p_dbg(p2p, "Received Invitation Request from " MACSTR " (freq=%d)", MAC2STR(sa), rx_freq); if (p2p_parse(data, len, &msg)) return; dev = p2p_get_device(p2p, sa); if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { p2p_dbg(p2p, "Invitation Request from unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, NULL, 0, data + 1, len - 1, 0)) { p2p_dbg(p2p, "Invitation Request add device failed " MACSTR, MAC2STR(sa)); status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; goto fail; } dev = p2p_get_device(p2p, sa); if (dev == NULL) { p2p_dbg(p2p, "Reject Invitation Request from unknown peer " MACSTR, MAC2STR(sa)); status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE; goto fail; } } if (!msg.group_id || !msg.channel_list) { p2p_dbg(p2p, "Mandatory attribute missing in Invitation Request from " MACSTR, MAC2STR(sa)); status = P2P_SC_FAIL_INVALID_PARAMS; goto fail; } if (msg.invitation_flags) persistent = *msg.invitation_flags & P2P_INVITATION_FLAGS_TYPE; else { /* Invitation Flags is a mandatory attribute starting from P2P * spec 1.06. As a backwards compatibility mechanism, assume * the request was for a persistent group if the attribute is * missing. */ p2p_dbg(p2p, "Mandatory Invitation Flags attribute missing from Invitation Request"); persistent = 1; } p2p_channels_union(&p2p->cfg->channels, &p2p->cfg->cli_channels, &all_channels); if (p2p_peer_channels_check(p2p, &all_channels, dev, msg.channel_list, msg.channel_list_len) < 0) { p2p_dbg(p2p, "No common channels found"); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } p2p_channels_dump(p2p, "own channels", &p2p->cfg->channels); p2p_channels_dump(p2p, "own client channels", &all_channels); p2p_channels_dump(p2p, "peer channels", &dev->channels); p2p_channels_intersect(&all_channels, &dev->channels, &intersection); p2p_channels_dump(p2p, "intersection", &intersection); if (p2p->cfg->invitation_process) { status = p2p->cfg->invitation_process( p2p->cfg->cb_ctx, sa, msg.group_bssid, msg.group_id, msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN, &go, group_bssid, &op_freq, persistent, &intersection, msg.dev_password_id_present ? msg.dev_password_id : -1); } if (go) { p2p_channels_intersect(&p2p->cfg->channels, &dev->channels, &intersection); p2p_channels_dump(p2p, "intersection(GO)", &intersection); if (intersection.reg_classes == 0) { p2p_dbg(p2p, "No common channels found (GO)"); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } } if (op_freq) { p2p_dbg(p2p, "Invitation processing forced frequency %d MHz", op_freq); if (p2p_freq_to_channel(op_freq, ®_class, &channel) < 0) { p2p_dbg(p2p, "Unknown forced freq %d MHz from invitation_process()", op_freq); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } if (!p2p_channels_includes(&intersection, reg_class, channel)) { p2p_dbg(p2p, "forced freq %d MHz not in the supported channels intersection", op_freq); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } if (status == P2P_SC_SUCCESS) channels = &intersection; } else { p2p_dbg(p2p, "No forced channel from invitation processing - figure out best one to use"); /* Default to own configuration as a starting point */ p2p->op_reg_class = p2p->cfg->op_reg_class; p2p->op_channel = p2p->cfg->op_channel; p2p_dbg(p2p, "Own default op_class %d channel %d", p2p->op_reg_class, p2p->op_channel); /* Use peer preference if specified and compatible */ if (msg.operating_channel) { int req_freq; req_freq = p2p_channel_to_freq( msg.operating_channel[3], msg.operating_channel[4]); p2p_dbg(p2p, "Peer operating channel preference: %d MHz", req_freq); if (req_freq > 0 && p2p_channels_includes(&intersection, msg.operating_channel[3], msg.operating_channel[4])) { p2p->op_reg_class = msg.operating_channel[3]; p2p->op_channel = msg.operating_channel[4]; p2p_dbg(p2p, "Use peer preference op_class %d channel %d", p2p->op_reg_class, p2p->op_channel); } else { p2p_dbg(p2p, "Cannot use peer channel preference"); } } /* Reselect the channel only for the case of the GO */ if (go && !p2p_channels_includes(&intersection, p2p->op_reg_class, p2p->op_channel)) { p2p_dbg(p2p, "Initially selected channel (op_class %d channel %d) not in channel intersection - try to reselect", p2p->op_reg_class, p2p->op_channel); p2p_reselect_channel(p2p, &intersection); p2p_dbg(p2p, "Re-selection result: op_class %d channel %d", p2p->op_reg_class, p2p->op_channel); if (!p2p_channels_includes(&intersection, p2p->op_reg_class, p2p->op_channel)) { p2p_dbg(p2p, "Peer does not support selected operating channel (reg_class=%u channel=%u)", p2p->op_reg_class, p2p->op_channel); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } } else if (go && !(dev->flags & P2P_DEV_FORCE_FREQ) && !p2p->cfg->cfg_op_channel) { p2p_dbg(p2p, "Try to reselect channel selection with peer information received; previously selected op_class %u channel %u", p2p->op_reg_class, p2p->op_channel); p2p_reselect_channel(p2p, &intersection); } /* * Use the driver preferred frequency list extension if * supported. */ p2p_check_pref_chan(p2p, go, dev, &msg); op_freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel); if (op_freq < 0) { p2p_dbg(p2p, "Unknown operational channel (country=%c%c reg_class=%u channel=%u)", p2p->cfg->country[0], p2p->cfg->country[1], p2p->op_reg_class, p2p->op_channel); status = P2P_SC_FAIL_NO_COMMON_CHANNELS; goto fail; } p2p_dbg(p2p, "Selected operating channel - %d MHz", op_freq); if (status == P2P_SC_SUCCESS) { reg_class = p2p->op_reg_class; channel = p2p->op_channel; channels = &intersection; } } fail: if (go && status == P2P_SC_SUCCESS && !is_zero_ether_addr(group_bssid)) bssid = group_bssid; else bssid = NULL; resp = p2p_build_invitation_resp(p2p, dev, msg.dialog_token, status, bssid, reg_class, channel, channels); if (resp == NULL) goto out; if (rx_freq > 0) freq = rx_freq; else freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel); if (freq < 0) { p2p_dbg(p2p, "Unknown regulatory class/channel"); goto out; } /* * Store copy of invitation data to be used when processing TX status * callback for the Acton frame. */ os_memcpy(p2p->inv_sa, sa, ETH_ALEN); if (msg.group_bssid) { os_memcpy(p2p->inv_group_bssid, msg.group_bssid, ETH_ALEN); p2p->inv_group_bssid_ptr = p2p->inv_group_bssid; } else p2p->inv_group_bssid_ptr = NULL; if (msg.group_id) { if (msg.group_id_len - ETH_ALEN <= SSID_MAX_LEN) { os_memcpy(p2p->inv_ssid, msg.group_id + ETH_ALEN, msg.group_id_len - ETH_ALEN); p2p->inv_ssid_len = msg.group_id_len - ETH_ALEN; } os_memcpy(p2p->inv_go_dev_addr, msg.group_id, ETH_ALEN); } else { p2p->inv_ssid_len = 0; os_memset(p2p->inv_go_dev_addr, 0, ETH_ALEN); } p2p->inv_status = status; p2p->inv_op_freq = op_freq; p2p->pending_action_state = P2P_PENDING_INVITATION_RESPONSE; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 50) < 0) { p2p_dbg(p2p, "Failed to send Action frame"); } out: wpabuf_free(resp); p2p_parse_free(&msg); }
void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len) { struct p2p_device *dev; struct p2p_message msg; struct p2p_channels intersection, *channels = NULL; p2p_dbg(p2p, "Received Invitation Response from " MACSTR, MAC2STR(sa)); dev = p2p_get_device(p2p, sa); if (dev == NULL) { p2p_dbg(p2p, "Ignore Invitation Response from unknown peer " MACSTR, MAC2STR(sa)); return; } if (dev != p2p->invite_peer) { p2p_dbg(p2p, "Ignore unexpected Invitation Response from peer " MACSTR, MAC2STR(sa)); return; } if (p2p_parse(data, len, &msg)) return; if (!msg.status) { p2p_dbg(p2p, "Mandatory Status attribute missing in Invitation Response from " MACSTR, MAC2STR(sa)); p2p_parse_free(&msg); return; } if (!msg.channel_list && *msg.status == P2P_SC_SUCCESS) { p2p_dbg(p2p, "Mandatory Channel List attribute missing in Invitation Response from " MACSTR, MAC2STR(sa)); #ifdef CONFIG_P2P_STRICT p2p_parse_free(&msg); return; #endif /* CONFIG_P2P_STRICT */ /* Try to survive without peer channel list */ channels = &p2p->channels; } else if (!msg.channel_list) { /* Non-success cases are not required to include Channel List */ channels = &p2p->channels; } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev, msg.channel_list, msg.channel_list_len) < 0) { p2p_dbg(p2p, "No common channels found"); p2p_parse_free(&msg); return; } else { p2p_channels_intersect(&p2p->channels, &dev->channels, &intersection); channels = &intersection; } if (p2p->cfg->invitation_result) { int freq = p2p_channel_to_freq(p2p->op_reg_class, p2p->op_channel); if (freq < 0) freq = 0; p2p->cfg->invitation_result(p2p->cfg->cb_ctx, *msg.status, msg.group_bssid, channels, sa, freq); } p2p_parse_free(&msg); p2p_clear_timeout(p2p); p2p_set_state(p2p, P2P_IDLE); p2p->invite_peer = NULL; }
void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa, const u8 *data, size_t len, int rx_freq) { struct p2p_message msg; struct p2p_device *dev; int freq; int reject = 1; struct wpabuf *resp; if (p2p_parse(data, len, &msg)) return; wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Received Provision Discovery Request from " MACSTR " with config methods 0x%x (freq=%d)", MAC2STR(sa), msg.wps_config_methods, rx_freq); dev = p2p_get_device(p2p, sa); if (dev == NULL || !(dev->flags & P2P_DEV_PROBE_REQ_ONLY)) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Provision Discovery Request from " "unknown peer " MACSTR, MAC2STR(sa)); if (p2p_add_device(p2p, sa, rx_freq, 0, data + 1, len - 1)) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Provision Discovery Request add device " "failed " MACSTR, MAC2STR(sa)); } } if (!(msg.wps_config_methods & (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_PUSHBUTTON))) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unsupported " "Config Methods in Provision Discovery Request"); goto out; } if (dev) dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY | P2P_DEV_PD_PEER_KEYPAD); if (msg.wps_config_methods & WPS_CONFIG_DISPLAY) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR " requested us to show a PIN on display", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_KEYPAD; } else if (msg.wps_config_methods & WPS_CONFIG_KEYPAD) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR " requested us to write its PIN using keypad", MAC2STR(sa)); if (dev) dev->flags |= P2P_DEV_PD_PEER_DISPLAY; } reject = 0; out: resp = p2p_build_prov_disc_resp(p2p, msg.dialog_token, reject ? 0 : msg.wps_config_methods); if (resp == NULL) { p2p_parse_free(&msg); return; } wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Sending Provision Discovery Response"); if (rx_freq > 0) freq = rx_freq; else freq = p2p_channel_to_freq(p2p->cfg->country, p2p->cfg->reg_class, p2p->cfg->channel); if (freq < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unknown regulatory class/channel"); wpabuf_free(resp); p2p_parse_free(&msg); return; } p2p->pending_action_state = P2P_NO_PENDING_ACTION; if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, p2p->cfg->dev_addr, wpabuf_head(resp), wpabuf_len(resp), 200) < 0) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Failed to send Action frame"); } wpabuf_free(resp); if (!reject && p2p->cfg->prov_disc_req) { const u8 *dev_addr = sa; if (msg.p2p_device_addr) dev_addr = msg.p2p_device_addr; p2p->cfg->prov_disc_req(p2p->cfg->cb_ctx, sa, msg.wps_config_methods, dev_addr, msg.pri_dev_type, msg.device_name, msg.config_methods, msg.capability ? msg.capability[0] : 0, msg.capability ? msg.capability[1] : 0); } p2p_parse_free(&msg); }