]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Add new_device flag to dev_found callback
authorJohannes Berg <johannes.berg@intel.com>
Thu, 24 Feb 2011 19:59:58 +0000 (21:59 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 24 Feb 2011 19:59:58 +0000 (21:59 +0200)
The DBus code will want to have perfect matching of dev_found and the
dev_lost it adds so it doesn't need to keep track internally. Enable
that with a new flag in the core that tracks whether we have already
notified about this -- the existing users can ignore it.

The part where this is always set to 1 if the new device is discovered
by a driver that has P2P in the driver is buggy -- the driver should
feed the P2P peer database and then that should feed the notification
here instead.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
src/drivers/driver_test.c
src/p2p/p2p.c
src/p2p/p2p.h
src/p2p/p2p_i.h
wpa_supplicant/events.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/p2p_supplicant.h

index 43b7c60c8c735231fb2d53e6febfddaad6e0306c..babf79a075a89c8e26934616d26638597c084969 100644 (file)
@@ -3118,7 +3118,7 @@ static void test_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
 
 
 static void test_dev_found(void *ctx, const u8 *addr,
-                          const struct p2p_peer_info *info)
+                          const struct p2p_peer_info *info, int new_device)
 {
        struct wpa_driver_test_data *drv = ctx;
        union wpa_event_data event;
index d65548439514d16422be4eacc1f8bc8ae4de7b35..d422499008ad5cf0f6a5658e515daa99cca45cc1 100644 (file)
@@ -390,7 +390,8 @@ static int p2p_add_group_clients(struct p2p_data *p2p, const u8 *go_dev_addr,
                        dev->oper_freq = freq;
                        p2p->cfg->dev_found(p2p->cfg->cb_ctx,
                                            dev->info.p2p_device_addr,
-                                           &dev->info);
+                                           &dev->info, 1);
+                       dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE;
                }
 
                os_memcpy(dev->interface_addr, cli->p2p_interface_addr,
@@ -539,8 +540,10 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq, int level,
                        "P2P: Do not report rejected device");
                return 0;
        }
-       p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info);
-       dev->flags |= P2P_DEV_REPORTED;
+
+       p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info,
+                           !(dev->flags & P2P_DEV_REPORTED_ONCE));
+       dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE;
 
        return 0;
 }
@@ -1118,7 +1121,9 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
                return;
        }
 
-       p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info);
+       p2p->cfg->dev_found(p2p->cfg->cb_ctx, addr, &dev->info,
+                           !(dev->flags & P2P_DEV_REPORTED_ONCE));
+       dev->flags |= P2P_DEV_REPORTED | P2P_DEV_REPORTED_ONCE;
 }
 
 
index 8324399a353e8c8320b11e9684c156324fb6f45f..baf51d8bb79ec9f8b7b0a0ab6cc00eff01e2b2b1 100644 (file)
@@ -430,6 +430,7 @@ struct p2p_config {
         * @ctx: Callback context from cb_ctx
         * @addr: Source address of the message triggering this notification
         * @info: P2P peer information
+        * @new_device: Inform if the peer is newly found
         *
         * This callback is used to notify that a new P2P Device has been
         * found. This may happen, e.g., during Search state based on scan
@@ -437,7 +438,8 @@ struct p2p_config {
         * Group Owner Negotiation Request.
         */
        void (*dev_found)(void *ctx, const u8 *addr,
-                         const struct p2p_peer_info *info);
+                         const struct p2p_peer_info *info,
+                         int new_device);
 
        /**
         * go_neg_req_rx - Notification of a receive GO Negotiation Request
index 0207c5bfdc4559a45a854be83ae4cd834f5119e3..91ba5fd1da9512299f080b4729d88e07633ea0bb 100644 (file)
@@ -89,6 +89,7 @@ struct p2p_device {
 #define P2P_DEV_GROUP_CLIENT_ONLY BIT(12)
 #define P2P_DEV_FORCE_FREQ BIT(13)
 #define P2P_DEV_PD_FOR_JOIN BIT(14)
+#define P2P_DEV_REPORTED_ONCE BIT(15)
        unsigned int flags;
 
        int status; /* enum p2p_status_code */
index f3644f60df7c25b1744448fa7c1439bd3e88c464..91f187346924aa5b754848e970c9f025643ec8bd 100644 (file)
@@ -2014,7 +2014,12 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
                peer_info.dev_capab = data->p2p_dev_found.dev_capab;
                peer_info.group_capab = data->p2p_dev_found.group_capab;
 
-               wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info);
+               /*
+                * FIX: new_device=1 is not necessarily correct. We should
+                * maintain a P2P peer database in wpa_supplicant and update
+                * this information based on whether the peer is truly new.
+                */
+               wpas_dev_found(wpa_s, data->p2p_dev_found.addr, &peer_info, 1);
                break;
                }
        case EVENT_P2P_GO_NEG_REQ_RX:
index e532ce2cd54253bbb7e6a2a580bae1fbd51b9959..cdfcd75a51c6e084055d8d759f8c9cac4b0d8fe1 100644 (file)
@@ -1131,7 +1131,8 @@ void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
 
 
 void wpas_dev_found(void *ctx, const u8 *addr,
-                   const struct p2p_peer_info *info)
+                   const struct p2p_peer_info *info,
+                   int new_device)
 {
        struct wpa_supplicant *wpa_s = ctx;
        char devtype[WPS_DEV_TYPE_BUFSIZE];
index ac4b13f93326dd2b85aa354f7c3b0543333c5bdb..5b3b1d2961b362e034c48a6166bb5469e49c3ebf 100644 (file)
@@ -64,7 +64,8 @@ void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies);
 void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s);
 void wpas_dev_found(void *ctx, const u8 *addr,
-                   const struct p2p_peer_info *info);
+                   const struct p2p_peer_info *info,
+                   int new_device);
 void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res);
 void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id);
 void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,