diff options
Diffstat (limited to 'src/p2p')
-rw-r--r--[-rwxr-xr-x] | src/p2p/p2p.c | 111 | ||||
-rw-r--r--[-rwxr-xr-x] | src/p2p/p2p.h | 54 | ||||
-rw-r--r-- | src/p2p/p2p_build.c | 10 | ||||
-rw-r--r-- | src/p2p/p2p_dev_disc.c | 10 | ||||
-rw-r--r-- | src/p2p/p2p_go_neg.c | 10 | ||||
-rw-r--r-- | src/p2p/p2p_group.c | 48 | ||||
-rw-r--r-- | src/p2p/p2p_i.h | 14 | ||||
-rw-r--r-- | src/p2p/p2p_invitation.c | 10 | ||||
-rw-r--r-- | src/p2p/p2p_parse.c | 10 | ||||
-rw-r--r-- | src/p2p/p2p_pd.c | 15 | ||||
-rw-r--r-- | src/p2p/p2p_sd.c | 10 | ||||
-rw-r--r-- | src/p2p/p2p_utils.c | 10 |
12 files changed, 193 insertions, 119 deletions
diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 8c768f6..d5884f2 100755..100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P module * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" @@ -17,10 +11,8 @@ #include "common.h" #include "eloop.h" #include "common/ieee802_11_defs.h" -#ifdef ANDROID_P2P -#include "common/wpa_ctrl.h" -#endif #include "common/ieee802_11_common.h" +#include "common/wpa_ctrl.h" #include "wps/wps_i.h" #include "p2p_i.h" #include "p2p.h" @@ -58,11 +50,38 @@ static void p2p_expire_peers(struct p2p_data *p2p) { struct p2p_device *dev, *n; struct os_time now; + size_t i; os_get_time(&now); dl_list_for_each_safe(dev, n, &p2p->devices, struct p2p_device, list) { if (dev->last_seen.sec + P2P_PEER_EXPIRATION_AGE >= now.sec) continue; + + if (p2p->cfg->go_connected && + p2p->cfg->go_connected(p2p->cfg->cb_ctx, + dev->info.p2p_device_addr)) { + /* + * We are connected as a client to a group in which the + * peer is the GO, so do not expire the peer entry. + */ + os_get_time(&dev->last_seen); + continue; + } + + for (i = 0; i < p2p->num_groups; i++) { + if (p2p_group_is_client_connected( + p2p->groups[i], dev->info.p2p_device_addr)) + break; + } + if (i < p2p->num_groups) { + /* + * The peer is connected as a client in a group where + * we are the GO, so do not expire the peer entry. + */ + os_get_time(&dev->last_seen); + continue; + } + wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Expiring old peer " "entry " MACSTR, MAC2STR(dev->info.p2p_device_addr)); dl_list_del(&dev->list); @@ -798,8 +817,8 @@ static void p2p_search(struct p2p_data *p2p) } if (p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, type, freq, - p2p->num_req_dev_types, p2p->req_dev_types) < 0) - { + p2p->num_req_dev_types, p2p->req_dev_types, + p2p->find_dev_id)) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Scan request failed"); p2p_continue_find(p2p); @@ -898,7 +917,8 @@ static void p2p_free_req_dev_types(struct p2p_data *p2p) int p2p_find(struct p2p_data *p2p, unsigned int timeout, enum p2p_discovery_type type, - unsigned int num_req_dev_types, const u8 *req_dev_types) + unsigned int num_req_dev_types, const u8 *req_dev_types, + const u8 *dev_id) { int res; @@ -920,6 +940,12 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout, p2p->num_req_dev_types = num_req_dev_types; } + if (dev_id) { + os_memcpy(p2p->find_dev_id_buf, dev_id, ETH_ALEN); + p2p->find_dev_id = p2p->find_dev_id_buf; + } else + p2p->find_dev_id = NULL; + p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; p2p_clear_timeout(p2p); p2p->cfg->stop_listen(p2p->cfg->cb_ctx); @@ -936,12 +962,12 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout, case P2P_FIND_PROGRESSIVE: res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_FULL, 0, p2p->num_req_dev_types, - p2p->req_dev_types); + p2p->req_dev_types, dev_id); break; case P2P_FIND_ONLY_SOCIAL: res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, P2P_SCAN_SOCIAL, 0, p2p->num_req_dev_types, - p2p->req_dev_types); + p2p->req_dev_types, dev_id); break; default: return -1; @@ -978,7 +1004,8 @@ int p2p_other_scan_completed(struct p2p_data *p2p) wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting pending P2P find " "now that previous scan was completed"); if (p2p_find(p2p, p2p->last_p2p_find_timeout, p2p->find_type, - p2p->num_req_dev_types, p2p->req_dev_types) < 0) + p2p->num_req_dev_types, p2p->req_dev_types, + p2p->find_dev_id) < 0) return 0; return 1; } @@ -989,11 +1016,9 @@ void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq) wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Stopping find"); eloop_cancel_timeout(p2p_find_timeout, p2p, NULL); p2p_clear_timeout(p2p); + if (p2p->state == P2P_SEARCH) + wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, P2P_EVENT_FIND_STOPPED); p2p_set_state(p2p, P2P_IDLE); -#ifdef ANDROID_P2P - wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, P2P_EVENT_FIND_STOPPED); -#endif - p2p_free_req_dev_types(p2p); p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING; p2p->go_neg_peer = NULL; @@ -2065,6 +2090,32 @@ int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end) } +int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr) +{ + struct wpabuf *p2p_ie; + struct p2p_message msg; + + p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, + P2P_IE_VENDOR_TYPE); + if (p2p_ie == NULL) + return -1; + os_memset(&msg, 0, sizeof(msg)); + if (p2p_parse_p2p_ie(p2p_ie, &msg)) { + wpabuf_free(p2p_ie); + return -1; + } + + if (msg.p2p_device_addr == NULL) { + wpabuf_free(p2p_ie); + return -1; + } + + os_memcpy(dev_addr, msg.p2p_device_addr, ETH_ALEN); + wpabuf_free(p2p_ie); + return 0; +} + + static void p2p_clear_go_neg(struct p2p_data *p2p) { p2p->go_neg_peer = NULL; @@ -2540,10 +2591,12 @@ void p2p_scan_res_handled(struct p2p_data *p2p) } -void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies) +void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id) { u8 *len = p2p_buf_add_ie_hdr(ies); p2p_buf_add_capability(ies, p2p->dev_capab, 0); + if (dev_id) + p2p_buf_add_device_id(ies, dev_id); if (p2p->cfg->reg_class && p2p->cfg->channel) p2p_buf_add_listen_channel(ies, p2p->cfg->country, p2p->cfg->reg_class, @@ -2792,6 +2845,20 @@ int p2p_listen_end(struct p2p_data *p2p, unsigned int freq) p2p_connect_send(p2p, p2p->go_neg_peer); return 1; } else if (p2p->state == P2P_SEARCH) { + if (p2p->p2p_scan_running) { + /* + * Search is already in progress. This can happen if + * an Action frame RX is reported immediately after + * the end of a remain-on-channel operation and the + * response frame to that is sent using an offchannel + * operation while in p2p_find. Avoid an attempt to + * restart a scan here. + */ + wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: p2p_scan " + "already in progress - do not try to start a " + "new one"); + return 1; + } p2p_search(p2p); return 1; } diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 05b4a16..6e3f232 100755..100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P module * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #ifndef P2P_H @@ -359,6 +353,7 @@ struct p2p_config { * @freq: Specific frequency (MHz) to scan or 0 for no restriction * @num_req_dev_types: Number of requested device types * @req_dev_types: Array containing requested device types + * @dev_id: Device ID to search for or %NULL to find all devices * Returns: 0 on success, -1 on failure * * This callback function is used to request a P2P scan or search @@ -382,7 +377,7 @@ struct p2p_config { */ int (*p2p_scan)(void *ctx, enum p2p_scan_type type, int freq, unsigned int num_req_dev_types, - const u8 *req_dev_types); + const u8 *req_dev_types, const u8 *dev_id); /** * send_probe_resp - Transmit a Probe Response frame @@ -705,6 +700,15 @@ struct p2p_config { * local failure in transmitting the Invitation Request. */ void (*invitation_result)(void *ctx, int status, const u8 *bssid); + + /** + * go_connected - Check whether we are connected to a GO + * @ctx: Callback context from cb_ctx + * @dev_addr: P2P Device Address of a GO + * Returns: 1 if we are connected as a P2P client to the specified GO + * or 0 if not. + */ + int (*go_connected)(void *ctx, const u8 *dev_addr); }; @@ -809,11 +813,13 @@ enum p2p_discovery_type { * @req_dev_types: Requested device types array, must be an array * containing num_req_dev_types * WPS_DEV_TYPE_LEN bytes; %NULL if no * requested device types. + * @dev_id: Device ID to search for or %NULL to find all devices * Returns: 0 on success, -1 on failure */ int p2p_find(struct p2p_data *p2p, unsigned int timeout, enum p2p_discovery_type type, - unsigned int num_req_dev_types, const u8 *req_dev_types); + unsigned int num_req_dev_types, const u8 *req_dev_types, + const u8 *dev_id); /** * p2p_stop_find - Stop P2P Find (Device Discovery) @@ -1324,6 +1330,11 @@ int p2p_group_notif_noa(struct p2p_group *group, const u8 *noa, int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps); /** + * p2p_group_match_dev_id - Match P2P Device Address in group with requested device id + */ +int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p); + +/** * p2p_group_go_discover - Send GO Discoverability Request to a group client * @group: P2P group context from p2p_group_init() * Returns: 0 on success (frame scheduled); -1 if client was not found @@ -1360,6 +1371,15 @@ int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end); int p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf, char *end); /** + * p2p_parse_dev_addr - Parse P2P Device Address from P2P IE(s) + * @ies: Information elements from scan results + * @ies_len: ies buffer length in octets + * @dev_addr: Buffer for returning P2P Device Address + * Returns: 0 on success or -1 if P2P Device Address could not be parsed + */ +int p2p_parse_dev_addr(const u8 *ies, size_t ies_len, u8 *dev_addr); + +/** * p2p_assoc_req_ie - Build P2P IE for (Re)Association Request frame * @p2p: P2P module context from p2p_init() * @bssid: BSSID @@ -1376,8 +1396,9 @@ int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf, * p2p_scan_ie - Build P2P IE for Probe Request * @p2p: P2P module context from p2p_init() * @ies: Buffer for writing P2P IE + * @dev_id: Device ID to search for or %NULL for any */ -void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies); +void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies, const u8 *dev_id); /** * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie @@ -1485,9 +1506,6 @@ void p2p_set_cross_connect(struct p2p_data *p2p, int enabled); int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr); -int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level, - const u8 *ies, size_t ies_len); - /** * p2p_set_intra_bss_dist - Set intra BSS distribution * @p2p: P2P module context from p2p_init() @@ -1543,6 +1561,14 @@ const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next); const u8 * p2p_group_get_dev_addr(struct p2p_group *group, const u8 *addr); /** + * p2p_group_is_client_connected - Check whether a specific client is connected + * @group: P2P group context from p2p_group_init() + * @addr: P2P Device Address of the client + * Returns: 1 if client is connected or 0 if not + */ +int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr); + +/** * p2p_get_peer_found - Get P2P peer info structure of a found peer * @p2p: P2P module context from p2p_init() * @addr: P2P Device Address of the peer or %NULL to indicate the first peer diff --git a/src/p2p/p2p_build.c b/src/p2p/p2p_build.c index a82e16d..2106964 100644 --- a/src/p2p/p2p_build.c +++ b/src/p2p/p2p_build.c @@ -2,14 +2,8 @@ * P2P - IE builder * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" diff --git a/src/p2p/p2p_dev_disc.c b/src/p2p/p2p_dev_disc.c index 47cc0fd..c976b7c 100644 --- a/src/p2p/p2p_dev_disc.c +++ b/src/p2p/p2p_dev_disc.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P Device Discoverability procedure * Copyright (c) 2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" diff --git a/src/p2p/p2p_go_neg.c b/src/p2p/p2p_go_neg.c index eb85f51..1a0c7d4 100644 --- a/src/p2p/p2p_go_neg.c +++ b/src/p2p/p2p_go_neg.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P Group Owner Negotiation * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" diff --git a/src/p2p/p2p_group.c b/src/p2p/p2p_group.c index 59d1507..fafd135 100644 --- a/src/p2p/p2p_group.c +++ b/src/p2p/p2p_group.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P group operations * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" @@ -490,6 +484,31 @@ int p2p_group_match_dev_type(struct p2p_group *group, struct wpabuf *wps) } +int p2p_group_match_dev_id(struct p2p_group *group, struct wpabuf *p2p) +{ + struct p2p_group_member *m; + struct p2p_message msg; + + os_memset(&msg, 0, sizeof(msg)); + if (p2p_parse_p2p_ie(p2p, &msg)) + return 1; /* Failed to parse - assume no filter on Device ID */ + + if (!msg.device_id) + return 1; /* No filter on Device ID */ + + if (os_memcmp(msg.device_id, group->p2p->cfg->dev_addr, ETH_ALEN) == 0) + return 1; /* Match with our P2P Device Address */ + + for (m = group->members; m; m = m->next) { + if (os_memcmp(msg.device_id, m->dev_addr, ETH_ALEN) == 0) + return 1; /* Match with group client P2P Device Address */ + } + + /* No match with Device ID */ + return 0; +} + + void p2p_group_notif_formation_done(struct p2p_group *group) { if (group == NULL) @@ -699,3 +718,16 @@ const u8 * p2p_iterate_group_members(struct p2p_group *group, void **next) return iter->addr; } + + +int p2p_group_is_client_connected(struct p2p_group *group, const u8 *dev_addr) +{ + struct p2p_group_member *m; + + for (m = group->members; m; m = m->next) { + if (os_memcmp(m->dev_addr, dev_addr, ETH_ALEN) == 0) + return 1; + } + + return 0; +} diff --git a/src/p2p/p2p_i.h b/src/p2p/p2p_i.h index 0dc33e7..8f9449e 100644 --- a/src/p2p/p2p_i.h +++ b/src/p2p/p2p_i.h @@ -2,14 +2,8 @@ * P2P - Internal definitions for P2P module * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #ifndef P2P_I_H @@ -381,6 +375,8 @@ struct p2p_data { /* Requested device types for find/search */ unsigned int num_req_dev_types; u8 *req_dev_types; + u8 *find_dev_id; + u8 find_dev_id_buf[ETH_ALEN]; struct p2p_group **groups; size_t num_groups; @@ -655,6 +651,8 @@ struct p2p_device * p2p_add_dev_from_go_neg_req(struct p2p_data *p2p, struct p2p_message *msg); void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr, struct p2p_device *dev, struct p2p_message *msg); +int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level, + const u8 *ies, size_t ies_len); struct p2p_device * p2p_get_device(struct p2p_data *p2p, const u8 *addr); struct p2p_device * p2p_get_device_interface(struct p2p_data *p2p, const u8 *addr); diff --git a/src/p2p/p2p_invitation.c b/src/p2p/p2p_invitation.c index bb2767d..417f1e7 100644 --- a/src/p2p/p2p_invitation.c +++ b/src/p2p/p2p_invitation.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P Invitation procedure * Copyright (c) 2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" diff --git a/src/p2p/p2p_parse.c b/src/p2p/p2p_parse.c index 5c5445a..a3ec57d 100644 --- a/src/p2p/p2p_parse.c +++ b/src/p2p/p2p_parse.c @@ -2,14 +2,8 @@ * P2P - IE parser * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" diff --git a/src/p2p/p2p_pd.c b/src/p2p/p2p_pd.c index 1ee59c5..55a3b90 100644 --- a/src/p2p/p2p_pd.c +++ b/src/p2p/p2p_pd.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P provision discovery * Copyright (c) 2009-2010, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" @@ -369,9 +363,8 @@ int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr, else dev->flags &= ~P2P_DEV_PD_FOR_JOIN; - if (p2p->go_neg_peer || - (p2p->state != P2P_IDLE && p2p->state != P2P_SEARCH && - p2p->state != P2P_LISTEN_ONLY)) { + if (p2p->state != P2P_IDLE && p2p->state != P2P_SEARCH && + p2p->state != P2P_LISTEN_ONLY) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Busy with other " "operations; postpone Provision Discovery Request " "with " MACSTR " (config methods 0x%x)", diff --git a/src/p2p/p2p_sd.c b/src/p2p/p2p_sd.c index f53d4b5..9e3588a 100644 --- a/src/p2p/p2p_sd.c +++ b/src/p2p/p2p_sd.c @@ -2,14 +2,8 @@ * Wi-Fi Direct - P2P service discovery * Copyright (c) 2009, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" diff --git a/src/p2p/p2p_utils.c b/src/p2p/p2p_utils.c index da4b6ed..bcc690d 100644 --- a/src/p2p/p2p_utils.c +++ b/src/p2p/p2p_utils.c @@ -2,14 +2,8 @@ * P2P - generic helper functions * Copyright (c) 2009, Atheros Communications * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * Alternatively, this software may be distributed under the terms of BSD - * license. - * - * See README and COPYING for more details. + * This software may be distributed under the terms of the BSD license. + * See README for more details. */ #include "includes.h" |