OSDN Git Service

Accumulative patch from commit d5b559b6418c2bd09663e0d09e93a6592357fdce
authorDmitry Shmidt <dimitrysh@google.com>
Mon, 20 May 2013 21:49:44 +0000 (14:49 -0700)
committerDmitry Shmidt <dimitrysh@google.com>
Mon, 20 May 2013 21:49:44 +0000 (14:49 -0700)
d5b559b WNM: Add disassociation timeout processing for ESS_DISASSOC
f65f539 GAS: Reduce query timeout to two seconds
7a56af5 GAS: Assign new dialog token even if previous one is free
9e1ecab GAS: Ignore replays if previous frag_id without dropping GAS session
fa7ae95 Add test code for fetching the last configured GTK
576bce9 P2P: Direct global ctrl_iface commands automatically for P2P
c4bf83a P2P: No duplicate AP-STA-CONNECTED/DISCONNECTED as global event
7793c95 Clean up AP-STA-CONNECTED/DISCONNECTED prints
92c4465 P2P: Mark P2P events global (not specific to interface)
ed496f1 P2P: Clean up debug prints
710ae9a P2P: Move p2p_find stopped event message into p2p_supplicant.c
47bfe49 Add wpa_msg_global() for global events
214e428 Allow global ctrl_iface monitors
89c7ac5 wpa_cli: Set buffer length the same as in wpa_supplicant_ctrl_iface_process()
faf9a85 Add band option (2.4 vs. 5) for filtering scans
b83b1b2 Android: Clarify keystore include directories
6f1127c Android: Add a top level Android.mk
d2a9e2c Abstract and Android sockets for global ctrl_iface
6fd5cea wpa_cli: Allow global interface to be used in interactive mode
2925756 wpa_supplicant: Add -G argument to specify global ctrl group
cf3bebf Allow global ctrl_iface to be used for per-interface commands
058c863 FT RRB: Fix a memory leak on error path

Change-Id: I32a4afb43894167a30c4b0df18fd4846a2945c7c
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
32 files changed:
Android.mk
hostapd/ctrl_iface.c
hostapd/hostapd_cli.c
src/ap/sta_info.c
src/ap/sta_info.h
src/ap/wpa_auth_ft.c
src/common/wpa_ctrl.c
src/drivers/driver_test.c
src/p2p/p2p.c
src/p2p/p2p.h
src/p2p/p2p_dev_disc.c
src/p2p/p2p_go_neg.c
src/p2p/p2p_group.c
src/p2p/p2p_i.h
src/p2p/p2p_invitation.c
src/p2p/p2p_pd.c
src/p2p/p2p_sd.c
src/utils/wpa_debug.c
src/utils/wpa_debug.h
wpa_supplicant/README
wpa_supplicant/ctrl_iface.c
wpa_supplicant/ctrl_iface_named_pipe.c
wpa_supplicant/ctrl_iface_udp.c
wpa_supplicant/ctrl_iface_unix.c
wpa_supplicant/gas_query.c
wpa_supplicant/main.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/scan.c
wpa_supplicant/wpa_cli.c
wpa_supplicant/wpa_supplicant.c
wpa_supplicant/wpa_supplicant_i.h
wpa_supplicant/wpas_glue.c

index 76afb77..4a74b24 100644 (file)
@@ -11,3 +11,6 @@ ifeq ($(WPA_SUPPLICANT_VERSION),VER_0_8_X)
 include $(LOCAL_PATH)/hostapd/Android.mk \
         $(LOCAL_PATH)/wpa_supplicant/Android.mk
 endif
+ifeq ($(WPA_SUPPLICANT_VERSION),VER_2_1_DEVEL)
+include $(call all-subdir-makefiles)
+endif
index 2153329..7fc520c 100644 (file)
@@ -537,14 +537,24 @@ static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
                                           const char *cmd)
 {
        u8 addr[ETH_ALEN];
-       const char *url;
+       const char *url, *timerstr;
        u8 buf[1000], *pos;
        struct ieee80211_mgmt *mgmt;
        size_t url_len;
+       int disassoc_timer;
 
        if (hwaddr_aton(cmd, addr))
                return -1;
-       url = cmd + 17;
+
+       timerstr = cmd + 17;
+       if (*timerstr != ' ')
+               return -1;
+       timerstr++;
+       disassoc_timer = atoi(timerstr);
+       if (disassoc_timer < 0 || disassoc_timer > 65535)
+               return -1;
+
+       url = os_strchr(timerstr, ' ');
        if (*url != ' ')
                return -1;
        url++;
@@ -564,8 +574,9 @@ static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
        mgmt->u.action.u.bss_tm_req.dialog_token = 1;
        mgmt->u.action.u.bss_tm_req.req_mode =
                WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
-       mgmt->u.action.u.bss_tm_req.disassoc_timer = host_to_le16(0);
-       mgmt->u.action.u.bss_tm_req.validity_interval = 0;
+       mgmt->u.action.u.bss_tm_req.disassoc_timer =
+               host_to_le16(disassoc_timer);
+       mgmt->u.action.u.bss_tm_req.validity_interval = 0x01;
 
        pos = mgmt->u.action.u.bss_tm_req.variable;
 
@@ -580,6 +591,25 @@ static int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
                return -1;
        }
 
+       /* send disassociation frame after time-out */
+       if (disassoc_timer) {
+               struct sta_info *sta;
+
+               sta = ap_get_sta(hapd, addr);
+               if (sta == NULL) {
+                       wpa_printf(MSG_DEBUG, "Station " MACSTR " not found "
+                                  "for ESS disassociation imminent message",
+                                  MAC2STR(addr));
+                       return -1;
+               }
+
+               sta->timeout_next = STA_DISASSOC_FROM_CLI;
+               eloop_cancel_timeout(ap_handle_timer, hapd, sta);
+               eloop_register_timeout(disassoc_timer / 1000,
+                                      disassoc_timer % 1000 * 1000,
+                                      ap_handle_timer, hapd, sta);
+       }
+
        return 0;
 }
 
@@ -1035,7 +1065,7 @@ static char * hostapd_ctrl_iface_path(struct hostapd_data *hapd)
 }
 
 
-static void hostapd_ctrl_iface_msg_cb(void *ctx, int level,
+static void hostapd_ctrl_iface_msg_cb(void *ctx, int level, int global,
                                      const char *txt, size_t len)
 {
        struct hostapd_data *hapd = ctx;
index 1537275..7071594 100644 (file)
@@ -593,14 +593,14 @@ static int hostapd_cli_cmd_ess_disassoc(struct wpa_ctrl *ctrl, int argc,
        char buf[300];
        int res;
 
-       if (argc < 2) {
-               printf("Invalid 'ess_disassoc' command - two arguments (STA "
-                      "addr and URL) are needed\n");
+       if (argc < 3) {
+               printf("Invalid 'ess_disassoc' command - three arguments (STA "
+                      "addr, disassoc timer, and URL) are needed\n");
                return -1;
        }
 
-       res = os_snprintf(buf, sizeof(buf), "ESS_DISASSOC %s %s",
-                         argv[0], argv[1]);
+       res = os_snprintf(buf, sizeof(buf), "ESS_DISASSOC %s %s %s",
+                         argv[0], argv[1], argv[2]);
        if (res < 0 || res >= (int) sizeof(buf))
                return -1;
        return wpa_ctrl_command(ctrl, buf);
index cbafb47..833f1b2 100644 (file)
@@ -283,6 +283,7 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
        struct hostapd_data *hapd = eloop_ctx;
        struct sta_info *sta = timeout_ctx;
        unsigned long next_time = 0;
+       int reason;
 
        wpa_printf(MSG_DEBUG, "%s: " MACSTR " flags=0x%x timeout_next=%d",
                   __func__, MAC2STR(sta->addr), sta->flags,
@@ -378,9 +379,11 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
                                hapd, sta->addr,
                                WLAN_REASON_PREV_AUTH_NOT_VALID);
                } else {
-                       hostapd_drv_sta_disassoc(
-                               hapd, sta->addr,
-                               WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
+                       reason = (sta->timeout_next == STA_DISASSOC) ?
+                               WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
+                               WLAN_REASON_PREV_AUTH_NOT_VALID;
+
+                       hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
                }
        }
 
@@ -394,6 +397,7 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
                                       hapd, sta);
                break;
        case STA_DISASSOC:
+       case STA_DISASSOC_FROM_CLI:
                ap_sta_set_authorized(hapd, sta, 0);
                sta->flags &= ~WLAN_STA_ASSOC;
                ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
@@ -405,14 +409,16 @@ void ap_handle_timer(void *eloop_ctx, void *timeout_ctx)
                hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
                               HOSTAPD_LEVEL_INFO, "disassociated due to "
                               "inactivity");
+               reason = (sta->timeout_next == STA_DISASSOC) ?
+                       WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY :
+                       WLAN_REASON_PREV_AUTH_NOT_VALID;
                sta->timeout_next = STA_DEAUTH;
                wpa_printf(MSG_DEBUG, "%s: register ap_handle_timer timeout "
                           "for " MACSTR " (%d seconds - AP_DEAUTH_DELAY)",
                           __func__, MAC2STR(sta->addr), AP_DEAUTH_DELAY);
                eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
                                       hapd, sta);
-               mlme_disassociate_indication(
-                       hapd, sta, WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
+               mlme_disassociate_indication(hapd, sta, reason);
                break;
        case STA_DEAUTH:
        case STA_REMOVE:
@@ -855,6 +861,7 @@ void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
                           int authorized)
 {
        const u8 *dev_addr = NULL;
+       char buf[100];
 #ifdef CONFIG_P2P
        u8 addr[ETH_ALEN];
 #endif /* CONFIG_P2P */
@@ -871,44 +878,29 @@ void ap_sta_set_authorized(struct hostapd_data *hapd, struct sta_info *sta,
                dev_addr = p2p_group_get_dev_addr(hapd->p2p_group, sta->addr);
 #endif /* CONFIG_P2P */
 
+       if (dev_addr)
+               os_snprintf(buf, sizeof(buf), MACSTR " p2p_dev_addr=" MACSTR,
+                           MAC2STR(sta->addr), MAC2STR(dev_addr));
+       else
+               os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(sta->addr));
+
        if (authorized) {
-               if (dev_addr)
-                       wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
-                               MACSTR " p2p_dev_addr=" MACSTR,
-                               MAC2STR(sta->addr), MAC2STR(dev_addr));
-               else
-                       wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED
-                               MACSTR, MAC2STR(sta->addr));
+               wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_CONNECTED "%s", buf);
+
                if (hapd->msg_ctx_parent &&
-                   hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
-                       wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
-                               AP_STA_CONNECTED MACSTR " p2p_dev_addr="
-                               MACSTR,
-                               MAC2STR(sta->addr), MAC2STR(dev_addr));
-               else if (hapd->msg_ctx_parent &&
-                        hapd->msg_ctx_parent != hapd->msg_ctx)
-                       wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
-                               AP_STA_CONNECTED MACSTR, MAC2STR(sta->addr));
+                   hapd->msg_ctx_parent != hapd->msg_ctx)
+                       wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
+                                         AP_STA_CONNECTED "%s", buf);
 
                sta->flags |= WLAN_STA_AUTHORIZED;
        } else {
-               if (dev_addr)
-                       wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
-                               MACSTR " p2p_dev_addr=" MACSTR,
-                               MAC2STR(sta->addr), MAC2STR(dev_addr));
-               else
-                       wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED
-                               MACSTR, MAC2STR(sta->addr));
+               wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
+
                if (hapd->msg_ctx_parent &&
-                   hapd->msg_ctx_parent != hapd->msg_ctx && dev_addr)
-                       wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
-                               AP_STA_DISCONNECTED MACSTR " p2p_dev_addr="
-                               MACSTR, MAC2STR(sta->addr), MAC2STR(dev_addr));
-               else if (hapd->msg_ctx_parent &&
-                        hapd->msg_ctx_parent != hapd->msg_ctx)
-                       wpa_msg(hapd->msg_ctx_parent, MSG_INFO,
-                               AP_STA_DISCONNECTED MACSTR,
-                               MAC2STR(sta->addr));
+                   hapd->msg_ctx_parent != hapd->msg_ctx)
+                       wpa_msg_no_global(hapd->msg_ctx_parent, MSG_INFO,
+                                         AP_STA_DISCONNECTED "%s", buf);
+
                sta->flags &= ~WLAN_STA_AUTHORIZED;
        }
 
index 32ea46e..f8f5a83 100644 (file)
@@ -62,7 +62,8 @@ struct sta_info {
        u8 previous_ap[6];
 
        enum {
-               STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH, STA_REMOVE
+               STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH, STA_REMOVE,
+               STA_DISASSOC_FROM_CLI
        } timeout_next;
 
        u16 deauth_reason;
index 791b48d..1bb5d97 100644 (file)
@@ -1218,8 +1218,10 @@ static int wpa_ft_rrb_rx_request(struct wpa_authenticator *wpa_auth,
        rlen = 2 + 2 * ETH_ALEN + 2 + resp_ies_len;
 
        frame = os_malloc(sizeof(*frame) + rlen);
-       if (frame == NULL)
+       if (frame == NULL) {
+               os_free(resp_ies);
                return -1;
+       }
        frame->frame_type = RSN_REMOTE_FRAME_TYPE_FT_RRB;
        frame->packet_type = FT_PACKET_RESPONSE;
        frame->action_length = host_to_le16(rlen);
index 58cbe6a..d9a7509 100644 (file)
@@ -82,6 +82,9 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
        int tries = 0;
        int flags;
 
+       if (ctrl_path == NULL)
+               return NULL;
+
        ctrl = os_malloc(sizeof(*ctrl));
        if (ctrl == NULL)
                return NULL;
@@ -126,13 +129,27 @@ try_again:
 #ifdef ANDROID
        chmod(ctrl->local.sun_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
        chown(ctrl->local.sun_path, AID_SYSTEM, AID_WIFI);
+
+       if (os_strncmp(ctrl_path, "@android:", 9) == 0) {
+               if (socket_local_client_connect(
+                           ctrl->s, ctrl_path + 9,
+                           ANDROID_SOCKET_NAMESPACE_RESERVED,
+                           SOCK_DGRAM) < 0) {
+                       close(ctrl->s);
+                       unlink(ctrl->local.sun_path);
+                       os_free(ctrl);
+                       return NULL;
+               }
+               return ctrl;
+       }
+
        /*
         * If the ctrl_path isn't an absolute pathname, assume that
         * it's the name of a socket in the Android reserved namespace.
         * Otherwise, it's a normal UNIX domain socket appearing in the
         * filesystem.
         */
-       if (ctrl_path != NULL && *ctrl_path != '/') {
+       if (*ctrl_path != '/') {
                char buf[21];
                os_snprintf(buf, sizeof(buf), "wpa_%s", ctrl_path);
                if (socket_local_client_connect(
@@ -149,12 +166,18 @@ try_again:
 #endif /* ANDROID */
 
        ctrl->dest.sun_family = AF_UNIX;
-       res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
-                        sizeof(ctrl->dest.sun_path));
-       if (res >= sizeof(ctrl->dest.sun_path)) {
-               close(ctrl->s);
-               os_free(ctrl);
-               return NULL;
+       if (os_strncmp(ctrl_path, "@abstract:", 10) == 0) {
+               ctrl->dest.sun_path[0] = '\0';
+               os_strlcpy(ctrl->dest.sun_path + 1, ctrl_path + 10,
+                          sizeof(ctrl->dest.sun_path) - 1);
+       } else {
+               res = os_strlcpy(ctrl->dest.sun_path, ctrl_path,
+                                sizeof(ctrl->dest.sun_path));
+               if (res >= sizeof(ctrl->dest.sun_path)) {
+                       close(ctrl->s);
+                       os_free(ctrl);
+                       return NULL;
+               }
        }
        if (connect(ctrl->s, (struct sockaddr *) &ctrl->dest,
                    sizeof(ctrl->dest)) < 0) {
index c99802a..541ebcc 100644 (file)
@@ -3195,6 +3195,12 @@ static void test_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
        /* TODO */
 }
 
+
+static void test_p2p_debug_print(void *ctx, int level, const char *msg)
+{
+       wpa_printf(level, "P2P: %s", msg);
+}
+
 #endif /* CONFIG_P2P */
 
 
@@ -3206,8 +3212,8 @@ static int wpa_driver_test_init_p2p(struct wpa_driver_test_data *drv)
        int i;
 
        os_memset(&p2p, 0, sizeof(p2p));
-       p2p.msg_ctx = drv->ctx;
        p2p.cb_ctx = drv;
+       p2p.debug_print = test_p2p_debug_print;
        p2p.p2p_scan = test_p2p_scan;
        p2p.send_action = test_send_action;
        p2p.send_action_done = test_send_action_done;
index cbd039a..0534b8c 100644 (file)
@@ -12,7 +12,6 @@
 #include "eloop.h"
 #include "common/ieee802_11_defs.h"
 #include "common/ieee802_11_common.h"
-#include "common/wpa_ctrl.h"
 #include "wps/wps_i.h"
 #include "p2p_i.h"
 #include "p2p.h"
@@ -119,8 +118,9 @@ static void p2p_expire_peers(struct p2p_data *p2p)
                        continue;
 #endif
 
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Expiring old peer "
-                       "entry " MACSTR, MAC2STR(dev->info.p2p_device_addr));
+               p2p_dbg(p2p, "Expiring old peer entry " MACSTR,
+                       MAC2STR(dev->info.p2p_device_addr));
+
 #ifdef ANDROID_P2P
                /* SD_FAIR_POLICY: Update the current sd_dev_list pointer to next device */
                if(&dev->list == p2p->sd_dev_list)
@@ -210,7 +210,7 @@ void p2p_clear_provisioning_info(struct p2p_data *p2p, const u8 *addr)
 
 void p2p_set_state(struct p2p_data *p2p, int new_state)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: State %s -> %s",
+       p2p_dbg(p2p, "State %s -> %s",
                p2p_state_txt(p2p->state), p2p_state_txt(new_state));
        p2p->state = new_state;
 }
@@ -218,8 +218,7 @@ void p2p_set_state(struct p2p_data *p2p, int new_state)
 
 void p2p_set_timeout(struct p2p_data *p2p, unsigned int sec, unsigned int usec)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Set timeout (state=%s): %u.%06u sec",
+       p2p_dbg(p2p, "Set timeout (state=%s): %u.%06u sec",
                p2p_state_txt(p2p->state), sec, usec);
        eloop_cancel_timeout(p2p_state_timeout, p2p, NULL);
        eloop_register_timeout(sec, usec, p2p_state_timeout, p2p, NULL);
@@ -228,8 +227,7 @@ void p2p_set_timeout(struct p2p_data *p2p, unsigned int sec, unsigned int usec)
 
 void p2p_clear_timeout(struct p2p_data *p2p)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Clear timeout (state=%s)",
-               p2p_state_txt(p2p->state));
+       p2p_dbg(p2p, "Clear timeout (state=%s)", p2p_state_txt(p2p->state));
        eloop_cancel_timeout(p2p_state_timeout, p2p, NULL);
 }
 
@@ -264,14 +262,12 @@ static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc)
        int freq;
        struct wpabuf *ies;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Starting short listen state (state=%s)",
+       p2p_dbg(p2p, "Starting short listen state (state=%s)",
                p2p_state_txt(p2p->state));
 
        freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel);
        if (freq < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unknown regulatory class/channel");
+               p2p_dbg(p2p, "Unknown regulatory class/channel");
                return;
        }
 
@@ -286,8 +282,7 @@ static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc)
                tu = p2p->cfg->max_listen * 1000 / 1024;
 
        if (tu == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Skip listen state "
-                       "since duration was 0 TU");
+               p2p_dbg(p2p, "Skip listen state since duration was 0 TU");
                p2p_set_timeout(p2p, 0, 0);
                return;
        }
@@ -302,8 +297,7 @@ static void p2p_listen_in_find(struct p2p_data *p2p, int dev_disc)
 
        if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, freq, 1024 * tu / 1000,
                    ies) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to start listen mode");
+               p2p_dbg(p2p, "Failed to start listen mode");
                p2p->pending_listen_freq = 0;
        }
        wpabuf_free(ies);
@@ -315,13 +309,11 @@ int p2p_listen(struct p2p_data *p2p, unsigned int timeout)
        int freq;
        struct wpabuf *ies;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Going to listen(only) state");
+       p2p_dbg(p2p, "Going to listen(only) state");
 
        freq = p2p_channel_to_freq(p2p->cfg->reg_class, p2p->cfg->channel);
        if (freq < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unknown regulatory class/channel");
+               p2p_dbg(p2p, "Unknown regulatory class/channel");
                return -1;
        }
 
@@ -331,13 +323,10 @@ int p2p_listen(struct p2p_data *p2p, unsigned int timeout)
 
        if (p2p->p2p_scan_running) {
                if (p2p->start_after_scan == P2P_AFTER_SCAN_CONNECT) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: p2p_scan running - connect is already "
-                               "pending - skip listen");
+                       p2p_dbg(p2p, "p2p_scan running - connect is already pending - skip listen");
                        return 0;
                }
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: p2p_scan running - delay start of listen state");
+               p2p_dbg(p2p, "p2p_scan running - delay start of listen state");
                p2p->start_after_scan = P2P_AFTER_SCAN_LISTEN;
                return 0;
        }
@@ -347,8 +336,7 @@ int p2p_listen(struct p2p_data *p2p, unsigned int timeout)
                return -1;
 
        if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, freq, timeout, ies) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to start listen mode");
+               p2p_dbg(p2p, "Failed to start listen mode");
                p2p->pending_listen_freq = 0;
                wpabuf_free(ies);
                return -1;
@@ -430,9 +418,7 @@ static struct p2p_device * p2p_create_device(struct p2p_data *p2p,
                        oldest = dev;
        }
        if (count + 1 > p2p->cfg->max_peers && oldest) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Remove oldest peer entry to make room for a new "
-                       "peer");
+               p2p_dbg(p2p, "Remove oldest peer entry to make room for a new peer");
 #ifdef ANDROID_P2P
                /* SD_FAIR_POLICY: Update the current sd_dev_list pointer to next device */
                if(&oldest->list == p2p->sd_dev_list)
@@ -546,8 +532,8 @@ static int p2p_add_group_clients(struct p2p_data *p2p, const u8 *go_dev_addr,
 }
 
 
-static void p2p_copy_wps_info(struct p2p_device *dev, int probe_req,
-                             const struct p2p_message *msg)
+static void p2p_copy_wps_info(struct p2p_data *p2p, struct p2p_device *dev,
+                             int probe_req, const struct p2p_message *msg)
 {
        os_memcpy(dev->info.device_name, msg->device_name,
                  sizeof(dev->info.device_name));
@@ -622,11 +608,11 @@ static void p2p_copy_wps_info(struct p2p_device *dev, int probe_req,
                        msg->config_methods : msg->wps_config_methods;
                if (new_config_methods &&
                    dev->info.config_methods != new_config_methods) {
-                       wpa_printf(MSG_DEBUG, "P2P: Update peer " MACSTR
-                                  " config_methods 0x%x -> 0x%x",
-                                  MAC2STR(dev->info.p2p_device_addr),
-                                  dev->info.config_methods,
-                                  new_config_methods);
+                       p2p_dbg(p2p, "Update peer " MACSTR
+                               " config_methods 0x%x -> 0x%x",
+                               MAC2STR(dev->info.p2p_device_addr),
+                               dev->info.config_methods,
+                               new_config_methods);
                        dev->info.config_methods = new_config_methods;
                }
        }
@@ -663,8 +649,7 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
 
        os_memset(&msg, 0, sizeof(msg));
        if (p2p_parse_ies(ies, ies_len, &msg)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to parse P2P IE for a device entry");
+               p2p_dbg(p2p, "Failed to parse P2P IE for a device entry");
                p2p_parse_free(&msg);
                return -1;
        }
@@ -674,18 +659,15 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
        else if (msg.device_id)
                p2p_dev_addr = msg.device_id;
        else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore scan data without P2P Device Info or "
-                       "P2P Device Id");
+               p2p_dbg(p2p, "Ignore scan data without P2P Device Info or P2P Device Id");
                p2p_parse_free(&msg);
                return -1;
        }
 
        if (!is_zero_ether_addr(p2p->peer_filter) &&
            os_memcmp(p2p_dev_addr, p2p->peer_filter, ETH_ALEN) != 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Do not add peer "
-                       "filter for " MACSTR " due to peer filter",
-                       MAC2STR(p2p_dev_addr));
+               p2p_dbg(p2p, "Do not add peer filter for " MACSTR
+                       " due to peer filter", MAC2STR(p2p_dev_addr));
                p2p_parse_free(&msg);
                return 0;
        }
@@ -707,9 +689,7 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
         */
        if (dev->last_seen.sec > 0 &&
            os_time_before(rx_time, &dev->last_seen)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Do not update peer "
-                       "entry based on old frame (rx_time=%u.%06u "
-                       "last_seen=%u.%06u)",
+               p2p_dbg(p2p, "Do not update peer entry based on old frame (rx_time=%u.%06u last_seen=%u.%06u)",
                        (unsigned int) rx_time->sec,
                        (unsigned int) rx_time->usec,
                        (unsigned int) dev->last_seen.sec,
@@ -740,18 +720,15 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
                else
                        ds_freq = 2407 + *msg.ds_params * 5;
                if (freq != ds_freq) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Update Listen frequency based on DS "
-                               "Parameter Set IE: %d -> %d MHz",
+                       p2p_dbg(p2p, "Update Listen frequency based on DS Parameter Set IE: %d -> %d MHz",
                                freq, ds_freq);
                        freq = ds_freq;
                }
        }
 
        if (dev->listen_freq && dev->listen_freq != freq && scan_res) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Update Listen frequency based on scan "
-                       "results (" MACSTR " %d -> %d MHz (DS param %d)",
+               p2p_dbg(p2p, "Update Listen frequency based on scan results ("
+                       MACSTR " %d -> %d MHz (DS param %d)",
                        MAC2STR(dev->info.p2p_device_addr), dev->listen_freq,
                        freq, msg.ds_params ? *msg.ds_params : -1);
        }
@@ -762,7 +739,7 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
        }
        dev->info.level = level;
 
-       p2p_copy_wps_info(dev, 0, &msg);
+       p2p_copy_wps_info(p2p, dev, 0, &msg);
 
        for (i = 0; i < P2P_MAX_WPS_VENDOR_EXT; i++) {
                wpabuf_free(dev->info.wps_vendor_ext[i]);
@@ -796,13 +773,11 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
        if (dev->flags & P2P_DEV_REPORTED)
                return 0;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Peer found with Listen frequency %d MHz "
-               "(rx_time=%u.%06u)", freq, (unsigned int) rx_time->sec,
+       p2p_dbg(p2p, "Peer found with Listen frequency %d MHz (rx_time=%u.%06u)",
+               freq, (unsigned int) rx_time->sec,
                (unsigned int) rx_time->usec);
        if (dev->flags & P2P_DEV_USER_REJECTED) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Do not report rejected device");
+               p2p_dbg(p2p, "Do not report rejected device");
                return 0;
        }
 
@@ -822,9 +797,8 @@ int p2p_add_device(struct p2p_data *p2p, const u8 *addr, int freq,
                 * Probe Response frame that includes the config_methods
                 * information.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Do not report peer " MACSTR " with unknown "
-                       "config methods", MAC2STR(addr));
+               p2p_dbg(p2p, "Do not report peer " MACSTR
+                       " with unknown config methods", MAC2STR(addr));
                return 0;
        }
 
@@ -913,8 +887,7 @@ static int p2p_get_next_prog_freq(struct p2p_data *p2p)
        }
 
        freq = p2p_channel_to_freq(reg_class, channel);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Next progressive search "
-               "channel: reg_class %u channel %u -> %d MHz",
+       p2p_dbg(p2p, "Next progressive search channel: reg_class %u channel %u -> %d MHz",
                reg_class, channel, freq);
        p2p->last_prog_scan_class = reg_class;
        p2p->last_prog_scan_chan = channel;
@@ -933,9 +906,7 @@ static void p2p_search(struct p2p_data *p2p)
        int res;
 
        if (p2p->drv_in_listen) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Driver is still "
-                       "in Listen state - wait for it to end before "
-                       "continuing");
+               p2p_dbg(p2p, "Driver is still in Listen state - wait for it to end before continuing");
                return;
        }
        p2p->cfg->stop_listen(p2p->cfg->cb_ctx);
@@ -943,27 +914,23 @@ static void p2p_search(struct p2p_data *p2p)
        if (p2p->find_type == P2P_FIND_PROGRESSIVE &&
            (freq = p2p_get_next_prog_freq(p2p)) > 0) {
                type = P2P_SCAN_SOCIAL_PLUS_ONE;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting search "
-                       "(+ freq %u)", freq);
+               p2p_dbg(p2p, "Starting search (+ freq %u)", freq);
        } else {
                type = P2P_SCAN_SOCIAL;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting search");
+               p2p_dbg(p2p, "Starting search");
        }
 
        res = p2p->cfg->p2p_scan(p2p->cfg->cb_ctx, type, freq,
                                 p2p->num_req_dev_types, p2p->req_dev_types,
                                 p2p->find_dev_id, pw_id);
        if (res < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Scan request failed");
+               p2p_dbg(p2p, "Scan request failed");
                p2p_continue_find(p2p);
        } else if (res == 1) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Could not start "
-                       "p2p_scan at this point - will try again after "
-                       "previous scan completes");
+               p2p_dbg(p2p, "Could not start p2p_scan at this point - will try again after previous scan completes");
                p2p_set_state(p2p, P2P_CONTINUE_SEARCH_WHEN_READY);
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Running p2p_scan");
+               p2p_dbg(p2p, "Running p2p_scan");
                p2p->p2p_scan_running = 1;
                eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL);
                eloop_register_timeout(P2P_SCAN_TIMEOUT, 0, p2p_scan_timeout,
@@ -975,7 +942,7 @@ static void p2p_search(struct p2p_data *p2p)
 static void p2p_find_timeout(void *eloop_ctx, void *timeout_ctx)
 {
        struct p2p_data *p2p = eloop_ctx;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Find timeout -> stop");
+       p2p_dbg(p2p, "Find timeout -> stop");
        p2p_stop_find(p2p);
 }
 
@@ -987,8 +954,7 @@ static int p2p_run_after_scan(struct p2p_data *p2p)
 
        if (p2p->after_scan_tx) {
                p2p->after_scan_tx_in_progress = 1;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send pending "
-                       "Action frame at p2p_scan completion");
+               p2p_dbg(p2p, "Send pending Action frame at p2p_scan completion");
                p2p->cfg->send_action(p2p->cfg->cb_ctx,
                                      p2p->after_scan_tx->freq,
                                      p2p->after_scan_tx->dst,
@@ -1016,19 +982,16 @@ static int p2p_run_after_scan(struct p2p_data *p2p)
        case P2P_AFTER_SCAN_NOTHING:
                break;
        case P2P_AFTER_SCAN_LISTEN:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Start previously "
-                       "requested Listen state");
+               p2p_dbg(p2p, "Start previously requested Listen state");
                p2p_listen(p2p, p2p->pending_listen_sec * 1000 +
                           p2p->pending_listen_usec / 1000);
                return 1;
        case P2P_AFTER_SCAN_CONNECT:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Start previously "
-                       "requested connect with " MACSTR,
+               p2p_dbg(p2p, "Start previously requested connect with " MACSTR,
                        MAC2STR(p2p->after_scan_peer));
                dev = p2p_get_device(p2p, p2p->after_scan_peer);
                if (dev == NULL) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer not "
-                               "known anymore");
+                       p2p_dbg(p2p, "Peer not known anymore");
                        break;
                }
                p2p_connect_send(p2p, dev);
@@ -1043,8 +1006,7 @@ static void p2p_scan_timeout(void *eloop_ctx, void *timeout_ctx)
 {
        struct p2p_data *p2p = eloop_ctx;
        int running;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: p2p_scan timeout "
-               "(running=%d)", p2p->p2p_scan_running);
+       p2p_dbg(p2p, "p2p_scan timeout (running=%d)", p2p->p2p_scan_running);
        running = p2p->p2p_scan_running;
        /* Make sure we recover from missed scan results callback */
        p2p->p2p_scan_running = 0;
@@ -1069,12 +1031,10 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout,
 {
        int res;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting find (type=%d)",
-               type);
+       p2p_dbg(p2p, "Starting find (type=%d)", type);
        os_get_time(&p2p->find_start);
        if (p2p->p2p_scan_running) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: p2p_scan is "
-                       "already running");
+               p2p_dbg(p2p, "p2p_scan is already running");
        }
 
        p2p_free_req_dev_types(p2p);
@@ -1126,21 +1086,18 @@ int p2p_find(struct p2p_data *p2p, unsigned int timeout,
        }
 
        if (res == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Running p2p_scan");
+               p2p_dbg(p2p, "Running p2p_scan");
                p2p->p2p_scan_running = 1;
                eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL);
                eloop_register_timeout(P2P_SCAN_TIMEOUT, 0, p2p_scan_timeout,
                                       p2p, NULL);
        } else if (res == 1) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Could not start "
-                       "p2p_scan at this point - will try again after "
-                       "previous scan completes");
+               p2p_dbg(p2p, "Could not start p2p_scan at this point - will try again after previous scan completes");
                res = 0;
                p2p_set_state(p2p, P2P_SEARCH_WHEN_READY);
                eloop_cancel_timeout(p2p_find_timeout, p2p, NULL);
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Failed to start "
-                       "p2p_scan");
+               p2p_dbg(p2p, "Failed to start p2p_scan");
                p2p_set_state(p2p, P2P_IDLE);
                eloop_cancel_timeout(p2p_find_timeout, p2p, NULL);
        }
@@ -1170,12 +1127,11 @@ int p2p_other_scan_completed(struct p2p_data *p2p)
        }
        if (p2p->state != P2P_SEARCH_WHEN_READY)
                return 0;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting pending P2P find "
-               "now that previous scan was completed");
+       p2p_dbg(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,
                     p2p->find_dev_id, p2p->search_delay) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, P2P_EVENT_FIND_STOPPED);
+               p2p->cfg->find_stopped(p2p->cfg->cb_ctx);
                return 0;
        }
        return 1;
@@ -1184,13 +1140,13 @@ int p2p_other_scan_completed(struct p2p_data *p2p)
 
 void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Stopping find");
+       p2p_dbg(p2p, "Stopping find");
        eloop_cancel_timeout(p2p_find_timeout, p2p, NULL);
        p2p_clear_timeout(p2p);
        if (p2p->state == P2P_SEARCH ||
            p2p->state == P2P_CONTINUE_SEARCH_WHEN_READY ||
            p2p->state == P2P_SEARCH_WHEN_READY)
-               wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, P2P_EVENT_FIND_STOPPED);
+               p2p->cfg->find_stopped(p2p->cfg->cb_ctx);
        p2p_set_state(p2p, P2P_IDLE);
        p2p_free_req_dev_types(p2p);
        p2p->start_after_scan = P2P_AFTER_SCAN_NOTHING;
@@ -1206,8 +1162,7 @@ void p2p_stop_find_for_freq(struct p2p_data *p2p, int freq)
 void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq)
 {
        if (freq > 0 && p2p->drv_in_listen == freq && p2p->in_listen) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Skip stop_listen "
-                       "since we are on correct channel for response");
+               p2p_dbg(p2p, "Skip stop_listen since we are on correct channel for response");
                return;
        }
        if (p2p->in_listen) {
@@ -1220,8 +1175,7 @@ void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq)
                 * when the operation gets canceled, so clear the internal
                 * variable that is tracking driver state.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Clear "
-                       "drv_in_listen (%d)", p2p->drv_in_listen);
+               p2p_dbg(p2p, "Clear drv_in_listen (%d)", p2p->drv_in_listen);
                p2p->drv_in_listen = 0;
        }
        p2p->cfg->stop_listen(p2p->cfg->cb_ctx);
@@ -1242,15 +1196,13 @@ static int p2p_prepare_channel_pref(struct p2p_data *p2p,
        unsigned int freq = force_freq ? force_freq : pref_freq;
 
        if (p2p_freq_to_channel(freq, &op_class, &op_channel) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported frequency %u MHz", freq);
+               p2p_dbg(p2p, "Unsupported frequency %u MHz", freq);
                return -1;
        }
 
        if (!p2p_channels_includes(&p2p->cfg->channels, op_class, op_channel)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Frequency %u MHz (oper_class %u channel %u) not "
-                       "allowed for P2P", freq, op_class, op_channel);
+               p2p_dbg(p2p, "Frequency %u MHz (oper_class %u channel %u) not allowed for P2P",
+                       freq, op_class, op_channel);
                return -1;
        }
 
@@ -1279,24 +1231,21 @@ static void p2p_prepare_channel_best(struct p2p_data *p2p)
            p2p_supported_freq(p2p, p2p->best_freq_overall) &&
            p2p_freq_to_channel(p2p->best_freq_overall, &op_class, &op_channel)
            == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Select best "
-                       "overall channel as operating channel preference");
+               p2p_dbg(p2p, "Select best overall channel as operating channel preference");
                p2p->op_reg_class = op_class;
                p2p->op_channel = op_channel;
        } else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_5 > 0 &&
                   p2p_supported_freq(p2p, p2p->best_freq_5) &&
                   p2p_freq_to_channel(p2p->best_freq_5, &op_class, &op_channel)
                   == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Select best 5 GHz "
-                       "channel as operating channel preference");
+               p2p_dbg(p2p, "Select best 5 GHz channel as operating channel preference");
                p2p->op_reg_class = op_class;
                p2p->op_channel = op_channel;
        } else if (!p2p->cfg->cfg_op_channel && p2p->best_freq_24 > 0 &&
                   p2p_supported_freq(p2p, p2p->best_freq_24) &&
                   p2p_freq_to_channel(p2p->best_freq_24, &op_class,
                                       &op_channel) == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Select best 2.4 "
-                       "GHz channel as operating channel preference");
+               p2p_dbg(p2p, "Select best 2.4 GHz channel as operating channel preference");
                p2p->op_reg_class = op_class;
                p2p->op_channel = op_channel;
        } else {
@@ -1331,9 +1280,7 @@ int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev,
        } else {
                p2p_prepare_channel_best(p2p);
        }
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Own preference for operation channel: "
-               "Operating Class %u Channel %u%s",
+       p2p_dbg(p2p, "Own preference for operation channel: Operating Class %u Channel %u%s",
                p2p->op_reg_class, p2p->op_channel,
                force_freq ? " (forced)" : "");
 
@@ -1375,8 +1322,7 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
 {
        struct p2p_device *dev;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Request to start group negotiation - peer=" MACSTR
+       p2p_dbg(p2p, "Request to start group negotiation - peer=" MACSTR
                "  GO Intent=%d  Intended Interface Address=" MACSTR
                " wps_method=%d persistent_group=%d pd_before_go_neg=%d",
                MAC2STR(peer_addr), go_intent, MAC2STR(own_interface_addr),
@@ -1384,8 +1330,7 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
 
        dev = p2p_get_device(p2p, peer_addr);
        if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Cannot connect to unknown P2P Device " MACSTR,
+               p2p_dbg(p2p, "Cannot connect to unknown P2P Device " MACSTR,
                        MAC2STR(peer_addr));
                return -1;
        }
@@ -1396,15 +1341,13 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
        if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
                if (!(dev->info.dev_capab &
                      P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Cannot connect to P2P Device " MACSTR
+                       p2p_dbg(p2p, "Cannot connect to P2P Device " MACSTR
                                " that is in a group and is not discoverable",
                                MAC2STR(peer_addr));
                        return -1;
                }
                if (dev->oper_freq <= 0) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Cannot connect to P2P Device " MACSTR
+                       p2p_dbg(p2p, "Cannot connect to P2P Device " MACSTR
                                " with incomplete information",
                                MAC2STR(peer_addr));
                        return -1;
@@ -1460,9 +1403,7 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
                 * new GO Negotiation, e.g., when the pending frame was from a
                 * previous attempt at starting a GO Negotiation.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Dropped "
-                       "previous pending Action frame TX that was waiting "
-                       "for p2p_scan completion");
+               p2p_dbg(p2p, "Dropped previous pending Action frame TX that was waiting for p2p_scan completion");
                os_free(p2p->after_scan_tx);
                p2p->after_scan_tx = NULL;
        }
@@ -1471,8 +1412,7 @@ int p2p_connect(struct p2p_data *p2p, const u8 *peer_addr,
        dev->status = P2P_SC_SUCCESS;
 
        if (p2p->p2p_scan_running) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: p2p_scan running - delay connect send");
+               p2p_dbg(p2p, "p2p_scan running - delay connect send");
                p2p->start_after_scan = P2P_AFTER_SCAN_CONNECT;
                os_memcpy(p2p->after_scan_peer, peer_addr, ETH_ALEN);
                return 0;
@@ -1492,8 +1432,7 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
 {
        struct p2p_device *dev;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Request to authorize group negotiation - peer=" MACSTR
+       p2p_dbg(p2p, "Request to authorize group negotiation - peer=" MACSTR
                "  GO Intent=%d  Intended Interface Address=" MACSTR
                " wps_method=%d  persistent_group=%d",
                MAC2STR(peer_addr), go_intent, MAC2STR(own_interface_addr),
@@ -1501,8 +1440,7 @@ int p2p_authorize(struct p2p_data *p2p, const u8 *peer_addr,
 
        dev = p2p_get_device(p2p, peer_addr);
        if (dev == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Cannot authorize unknown P2P Device " MACSTR,
+               p2p_dbg(p2p, "Cannot authorize unknown P2P Device " MACSTR,
                        MAC2STR(peer_addr));
                return -1;
        }
@@ -1539,15 +1477,14 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
 {
        os_get_time(&dev->last_seen);
 
-       p2p_copy_wps_info(dev, 0, msg);
+       p2p_copy_wps_info(p2p, dev, 0, msg);
 
        if (msg->listen_channel) {
                int freq;
                freq = p2p_channel_to_freq(msg->listen_channel[3],
                                           msg->listen_channel[4]);
                if (freq < 0) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Unknown peer Listen channel: "
+                       p2p_dbg(p2p, "Unknown peer Listen channel: "
                                "country=%c%c(0x%02x) reg_class=%u channel=%u",
                                msg->listen_channel[0],
                                msg->listen_channel[1],
@@ -1555,8 +1492,8 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
                                msg->listen_channel[3],
                                msg->listen_channel[4]);
                } else {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Update "
-                               "peer " MACSTR " Listen channel: %u -> %u MHz",
+                       p2p_dbg(p2p, "Update peer " MACSTR
+                               " Listen channel: %u -> %u MHz",
                                MAC2STR(dev->info.p2p_device_addr),
                                dev->listen_freq, freq);
                        dev->listen_freq = freq;
@@ -1570,12 +1507,9 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
 
        if (dev->flags & P2P_DEV_PROBE_REQ_ONLY) {
                dev->flags &= ~P2P_DEV_PROBE_REQ_ONLY;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Completed device entry based on data from "
-                       "GO Negotiation Request");
+               p2p_dbg(p2p, "Completed device entry based on data from GO Negotiation Request");
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Created device entry based on GO Neg Req: "
+               p2p_dbg(p2p, "Created device entry based on GO Neg Req: "
                        MACSTR " dev_capab=0x%x group_capab=0x%x name='%s' "
                        "listen_freq=%d",
                        MAC2STR(dev->info.p2p_device_addr),
@@ -1586,8 +1520,7 @@ void p2p_add_dev_info(struct p2p_data *p2p, const u8 *addr,
        dev->flags &= ~P2P_DEV_GROUP_CLIENT_ONLY;
 
        if (dev->flags & P2P_DEV_USER_REJECTED) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Do not report rejected device");
+               p2p_dbg(p2p, "Do not report rejected device");
                return;
        }
 
@@ -1623,10 +1556,8 @@ void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer)
        int freqs;
        size_t i, j;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Negotiation with " MACSTR " completed (%s will be "
-               "GO)", MAC2STR(peer->info.p2p_device_addr),
-               go ? "local end" : "peer");
+       p2p_dbg(p2p, "GO Negotiation with " MACSTR " completed (%s will be GO)",
+               MAC2STR(peer->info.p2p_device_addr), go ? "local end" : "peer");
 
        os_memset(&res, 0, sizeof(res));
        res.role_go = go;
@@ -1688,8 +1619,7 @@ void p2p_go_complete(struct p2p_data *p2p, struct p2p_device *peer)
 static void p2p_rx_p2p_action(struct p2p_data *p2p, const u8 *sa,
                              const u8 *data, size_t len, int rx_freq)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: RX P2P Public Action from " MACSTR, MAC2STR(sa));
+       p2p_dbg(p2p, "RX P2P Public Action from " MACSTR, MAC2STR(sa));
        wpa_hexdump(MSG_MSGDUMP, "P2P: P2P Public Action contents", data, len);
 
        if (len < 1)
@@ -1725,8 +1655,7 @@ static void p2p_rx_p2p_action(struct p2p_data *p2p, const u8 *sa,
                p2p_process_dev_disc_resp(p2p, sa, data + 1, len - 1);
                break;
        default:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported P2P Public Action frame type %d",
+               p2p_dbg(p2p, "Unsupported P2P Public Action frame type %d",
                        data[0]);
                break;
        }
@@ -1801,16 +1730,14 @@ void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
        len--;
 
        /* P2P action frame */
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: RX P2P Action from " MACSTR, MAC2STR(sa));
+       p2p_dbg(p2p, "RX P2P Action from " MACSTR, MAC2STR(sa));
        wpa_hexdump(MSG_MSGDUMP, "P2P: P2P Action contents", data, len);
 
        if (len < 1)
                return;
        switch (data[0]) {
        case P2P_NOA:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Received P2P Action - Notice of Absence");
+               p2p_dbg(p2p, "Received P2P Action - Notice of Absence");
                /* TODO */
                break;
        case P2P_PRESENCE_REQ:
@@ -1823,8 +1750,7 @@ void p2p_rx_action(struct p2p_data *p2p, const u8 *da, const u8 *sa,
                p2p_process_go_disc_req(p2p, da, sa, data + 1, len - 1, freq);
                break;
        default:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Received P2P Action - unknown type %u", data[0]);
+               p2p_dbg(p2p, "Received P2P Action - unknown type %u", data[0]);
                break;
        }
 }
@@ -1900,7 +1826,7 @@ static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr,
                                                       msg.listen_channel[4]);
        }
 
-       p2p_copy_wps_info(dev, 1, &msg);
+       p2p_copy_wps_info(p2p, dev, 1, &msg);
 
        if (msg.wfd_subelems) {
                wpabuf_free(dev->info.wfd_subelems);
@@ -1909,8 +1835,7 @@ static void p2p_add_dev_from_probe_req(struct p2p_data *p2p, const u8 *addr,
 
        p2p_parse_free(&msg);
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Created device entry based on Probe Req: " MACSTR
+       p2p_dbg(p2p, "Created device entry based on Probe Req: " MACSTR
                " dev_capab=0x%x group_capab=0x%x name='%s' listen_freq=%d",
                MAC2STR(dev->info.p2p_device_addr), dev->info.dev_capab,
                dev->info.group_capab, dev->info.device_name,
@@ -2152,8 +2077,7 @@ p2p_reply_probe(struct p2p_data *p2p, const u8 *addr, const u8 *dst,
                return P2P_PREQ_NOT_PROCESSED;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Reply to P2P Probe Request in Listen state");
+       p2p_dbg(p2p, "Reply to P2P Probe Request in Listen state");
 
        /*
         * We do not really have a specific BSS that this frame is advertising,
@@ -2232,9 +2156,7 @@ p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst,
            == 0 &&
            !(p2p->go_neg_peer->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
                /* Received a Probe Request from GO Negotiation peer */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Found GO Negotiation peer - try to start GO "
-                       "negotiation from timeout");
+               p2p_dbg(p2p, "Found GO Negotiation peer - try to start GO negotiation from timeout");
                eloop_cancel_timeout(p2p_go_neg_start, p2p, NULL);
                eloop_register_timeout(0, 0, p2p_go_neg_start, p2p, NULL);
                return P2P_PREQ_PROCESSED;
@@ -2245,9 +2167,7 @@ p2p_probe_req_rx(struct p2p_data *p2p, const u8 *addr, const u8 *dst,
            os_memcmp(addr, p2p->invite_peer->info.p2p_device_addr, ETH_ALEN)
            == 0) {
                /* Received a Probe Request from Invite peer */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Found Invite peer - try to start Invite from "
-                       "timeout");
+               p2p_dbg(p2p, "Found Invite peer - try to start Invite from timeout");
                eloop_register_timeout(0, 0, p2p_invite_start, p2p, NULL);
                return P2P_PREQ_PROCESSED;
        }
@@ -2422,24 +2342,20 @@ static void p2p_clear_go_neg(struct p2p_data *p2p)
 void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr)
 {
        if (p2p->go_neg_peer == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No pending Group Formation - "
-                       "ignore WPS registration success notification");
+               p2p_dbg(p2p, "No pending Group Formation - ignore WPS registration success notification");
                return; /* No pending Group Formation */
        }
 
        if (os_memcmp(mac_addr, p2p->go_neg_peer->intended_addr, ETH_ALEN) !=
            0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore WPS registration success notification "
-                       "for " MACSTR " (GO Negotiation peer " MACSTR ")",
+               p2p_dbg(p2p, "Ignore WPS registration success notification for "
+                       MACSTR " (GO Negotiation peer " MACSTR ")",
                        MAC2STR(mac_addr),
                        MAC2STR(p2p->go_neg_peer->intended_addr));
                return; /* Ignore unexpected peer address */
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Group Formation completed successfully with " MACSTR,
+       p2p_dbg(p2p, "Group Formation completed successfully with " MACSTR,
                MAC2STR(mac_addr));
 
        p2p_clear_go_neg(p2p);
@@ -2449,14 +2365,11 @@ void p2p_wps_success_cb(struct p2p_data *p2p, const u8 *mac_addr)
 void p2p_group_formation_failed(struct p2p_data *p2p)
 {
        if (p2p->go_neg_peer == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No pending Group Formation - "
-                       "ignore group formation failure notification");
+               p2p_dbg(p2p, "No pending Group Formation - ignore group formation failure notification");
                return; /* No pending Group Formation */
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Group Formation failed with " MACSTR,
+       p2p_dbg(p2p, "Group Formation failed with " MACSTR,
                MAC2STR(p2p->go_neg_peer->intended_addr));
 
        p2p_clear_go_neg(p2p);
@@ -2593,8 +2506,7 @@ int p2p_unauthorize(struct p2p_data *p2p, const u8 *addr)
        if (dev == NULL)
                return -1;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Unauthorizing " MACSTR,
-               MAC2STR(addr));
+       p2p_dbg(p2p, "Unauthorizing " MACSTR, MAC2STR(addr));
 
        if (p2p->go_neg_peer == dev)
                p2p->go_neg_peer = NULL;
@@ -2795,8 +2707,7 @@ void p2p_continue_find(struct p2p_data *p2p)
                                break;
                } else if (dev->req_config_methods &&
                           !(dev->flags & P2P_DEV_PD_FOR_JOIN)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send "
-                               "pending Provision Discovery Request to "
+                       p2p_dbg(p2p, "Send pending Provision Discovery Request to "
                                MACSTR " (config methods 0x%x)",
                                MAC2STR(dev->info.p2p_device_addr),
                                dev->req_config_methods);
@@ -2811,8 +2722,7 @@ void p2p_continue_find(struct p2p_data *p2p)
 
 static void p2p_sd_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Service Discovery Query TX callback: success=%d",
+       p2p_dbg(p2p, "Service Discovery Query TX callback: success=%d",
                success);
        p2p->pending_action_state = P2P_NO_PENDING_ACTION;
 
@@ -2826,8 +2736,7 @@ static void p2p_sd_cb(struct p2p_data *p2p, int success)
        }
 
        if (p2p->sd_peer == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No SD peer entry known");
+               p2p_dbg(p2p, "No SD peer entry known");
                p2p_continue_find(p2p);
                return;
        }
@@ -2861,8 +2770,7 @@ static void p2p_retry_pd(struct p2p_data *p2p)
                if (!dev->req_config_methods)
                        continue;
 
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send "
-                       "pending Provision Discovery Request to "
+               p2p_dbg(p2p, "Send pending Provision Discovery Request to "
                        MACSTR " (config methods 0x%x)",
                        MAC2STR(dev->info.p2p_device_addr),
                        dev->req_config_methods);
@@ -2875,8 +2783,7 @@ static void p2p_retry_pd(struct p2p_data *p2p)
 
 static void p2p_prov_disc_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Provision Discovery Request TX callback: success=%d",
+       p2p_dbg(p2p, "Provision Discovery Request TX callback: success=%d",
                success);
 
        /*
@@ -2943,8 +2850,8 @@ int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
                 * that have based on frames received after the last p2p_find
                 * operation was started.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Ignore old scan "
-                       "result for " MACSTR " (rx_time=%u.%06u)",
+               p2p_dbg(p2p, "Ignore old scan result for " MACSTR
+                       " (rx_time=%u.%06u)",
                        MAC2STR(bssid), (unsigned int) rx_time->sec,
                        (unsigned int) rx_time->usec);
                return 0;
@@ -2959,8 +2866,7 @@ int p2p_scan_res_handler(struct p2p_data *p2p, const u8 *bssid, int freq,
 void p2p_scan_res_handled(struct p2p_data *p2p)
 {
        if (!p2p->p2p_scan_running) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: p2p_scan was not "
-                       "running, but scan results received");
+               p2p_dbg(p2p, "p2p_scan was not running, but scan results received");
        }
        p2p->p2p_scan_running = 0;
        eloop_cancel_timeout(p2p_scan_timeout, p2p, NULL);
@@ -3022,13 +2928,10 @@ static void p2p_go_neg_req_cb(struct p2p_data *p2p, int success)
        struct p2p_device *dev = p2p->go_neg_peer;
        int timeout;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Negotiation Request TX callback: success=%d",
-               success);
+       p2p_dbg(p2p, "GO Negotiation Request TX callback: success=%d", success);
 
        if (dev == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No pending GO Negotiation");
+               p2p_dbg(p2p, "No pending GO Negotiation");
                return;
        }
 
@@ -3045,9 +2948,7 @@ static void p2p_go_neg_req_cb(struct p2p_data *p2p, int success)
        if (!success &&
            (dev->info.dev_capab & P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY) &&
            !is_zero_ether_addr(dev->member_in_go_dev)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Peer " MACSTR " did not acknowledge request - "
-                       "try to use device discoverability through its GO",
+               p2p_dbg(p2p, "Peer " MACSTR " did not acknowledge request - try to use device discoverability through its GO",
                        MAC2STR(dev->info.p2p_device_addr));
                p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
                p2p_send_dev_disc_req(p2p, dev);
@@ -3078,13 +2979,10 @@ static void p2p_go_neg_req_cb(struct p2p_data *p2p, int success)
 
 static void p2p_go_neg_resp_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Negotiation Response TX callback: success=%d",
+       p2p_dbg(p2p, "GO Negotiation Response TX callback: success=%d",
                success);
        if (!p2p->go_neg_peer && p2p->state == P2P_PROVISIONING) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore TX callback event - GO Negotiation is "
-                       "not running anymore");
+               p2p_dbg(p2p, "Ignore TX callback event - GO Negotiation is not running anymore");
                return;
        }
        p2p_set_state(p2p, P2P_CONNECT);
@@ -3095,9 +2993,7 @@ static void p2p_go_neg_resp_cb(struct p2p_data *p2p, int success)
 static void p2p_go_neg_resp_failure_cb(struct p2p_data *p2p, int success,
                                       const u8 *addr)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Negotiation Response (failure) TX callback: "
-               "success=%d", success);
+       p2p_dbg(p2p, "GO Negotiation Response (failure) TX callback: success=%d", success);
        if (p2p->go_neg_peer && p2p->go_neg_peer->status != P2P_SC_SUCCESS) {
                p2p_go_neg_failed(p2p, p2p->go_neg_peer,
                                  p2p->go_neg_peer->status);
@@ -3116,9 +3012,7 @@ static void p2p_go_neg_conf_cb(struct p2p_data *p2p,
 {
        struct p2p_device *dev;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Negotiation Confirm TX callback: result=%d",
-               result);
+       p2p_dbg(p2p, "GO Negotiation Confirm TX callback: result=%d", result);
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
        if (result == P2P_SEND_ACTION_FAILED) {
                p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1);
@@ -3135,10 +3029,7 @@ static void p2p_go_neg_conf_cb(struct p2p_data *p2p,
                 * peer did indeed receive the frame, continue regardless of
                 * the TX status.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Assume GO Negotiation Confirm TX was actually "
-                       "received by the peer even though Ack was not "
-                       "reported");
+               p2p_dbg(p2p, "Assume GO Negotiation Confirm TX was actually received by the peer even though Ack was not reported");
        }
 
        dev = p2p->go_neg_peer;
@@ -3156,8 +3047,7 @@ void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
        enum p2p_pending_action_state state;
        int success;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Action frame TX callback (state=%d freq=%u dst=" MACSTR
+       p2p_dbg(p2p, "Action frame TX callback (state=%d freq=%u dst=" MACSTR
                " src=" MACSTR " bssid=" MACSTR " result=%d",
                p2p->pending_action_state, freq, MAC2STR(dst), MAC2STR(src),
                MAC2STR(bssid), result);
@@ -3172,9 +3062,7 @@ void p2p_send_action_cb(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
                            p2p_run_after_scan(p2p))
                                break;
                        if (p2p->state == P2P_SEARCH) {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: Continue find after "
-                                       "after_scan_tx completion");
+                               p2p_dbg(p2p, "Continue find after after_scan_tx completion");
                                p2p_continue_find(p2p);
                        }
                }
@@ -3222,23 +3110,18 @@ void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq,
                   unsigned int duration)
 {
        if (freq == p2p->pending_client_disc_freq) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Client discoverability remain-awake completed");
+               p2p_dbg(p2p, "Client discoverability remain-awake completed");
                p2p->pending_client_disc_freq = 0;
                return;
        }
 
        if (freq != p2p->pending_listen_freq) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected listen callback for freq=%u "
-                       "duration=%u (pending_listen_freq=%u)",
+               p2p_dbg(p2p, "Unexpected listen callback for freq=%u duration=%u (pending_listen_freq=%u)",
                        freq, duration, p2p->pending_listen_freq);
                return;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Starting Listen timeout(%u,%u) on freq=%u based on "
-               "callback",
+       p2p_dbg(p2p, "Starting Listen timeout(%u,%u) on freq=%u based on callback",
                p2p->pending_listen_sec, p2p->pending_listen_usec,
                p2p->pending_listen_freq);
        p2p->in_listen = 1;
@@ -3259,17 +3142,14 @@ void p2p_listen_cb(struct p2p_data *p2p, unsigned int freq,
 
 int p2p_listen_end(struct p2p_data *p2p, unsigned int freq)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Driver ended Listen "
-               "state (freq=%u)", freq);
+       p2p_dbg(p2p, "Driver ended Listen state (freq=%u)", freq);
        p2p->drv_in_listen = 0;
        if (p2p->in_listen)
                return 0; /* Internal timeout will trigger the next step */
 
        if (p2p->state == P2P_CONNECT_LISTEN && p2p->go_neg_peer) {
                if (p2p->go_neg_peer->connect_reqs >= 120) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Timeout on sending GO Negotiation "
-                               "Request without getting response");
+                       p2p_dbg(p2p, "Timeout on sending GO Negotiation Request without getting response");
                        p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1);
                        return 0;
                }
@@ -3287,9 +3167,7 @@ int p2p_listen_end(struct p2p_data *p2p, unsigned int freq)
                          * 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");
+                       p2p_dbg(p2p, "p2p_scan already in progress - do not try to start a new one");
                        return 1;
                }
                if (p2p->pending_listen_freq) {
@@ -3298,15 +3176,12 @@ int p2p_listen_end(struct p2p_data *p2p, unsigned int freq)
                         * offchannel operation for some reason. p2p_search()
                         * will be started from internal timeout.
                         */
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Listen "
-                               "operation did not seem to start - delay "
-                               "search phase to avoid busy loop");
+                       p2p_dbg(p2p, "Listen operation did not seem to start - delay search phase to avoid busy loop");
                        p2p_set_timeout(p2p, 0, 100000);
                        return 1;
                }
                if (p2p->search_delay) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Delay "
-                               "search operation by %u ms",
+                       p2p_dbg(p2p, "Delay search operation by %u ms",
                                p2p->search_delay);
                        p2p_set_timeout(p2p, p2p->search_delay / 1000,
                                        (p2p->search_delay % 1000) * 1000);
@@ -3325,17 +3200,14 @@ static void p2p_timeout_connect(struct p2p_data *p2p)
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
        if (p2p->go_neg_peer &&
            (p2p->go_neg_peer->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Wait for GO "
-                       "Negotiation Confirm timed out - assume GO "
-                       "Negotiation failed");
+               p2p_dbg(p2p, "Wait for GO Negotiation Confirm timed out - assume GO Negotiation failed");
                p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1);
                return;
        }
        if (p2p->go_neg_peer &&
            (p2p->go_neg_peer->flags & P2P_DEV_PEER_WAITING_RESPONSE) &&
            p2p->go_neg_peer->connect_reqs < 120) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer expected to "
-                       "wait our response - skip listen");
+               p2p_dbg(p2p, "Peer expected to wait our response - skip listen");
                p2p_connect_send(p2p, p2p->go_neg_peer);
                return;
        }
@@ -3349,16 +3221,12 @@ static void p2p_timeout_connect_listen(struct p2p_data *p2p)
 {
        if (p2p->go_neg_peer) {
                if (p2p->drv_in_listen) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Driver is "
-                               "still in Listen state; wait for it to "
-                               "complete");
+                       p2p_dbg(p2p, "Driver is still in Listen state; wait for it to complete");
                        return;
                }
 
                if (p2p->go_neg_peer->connect_reqs >= 120) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Timeout on sending GO Negotiation "
-                               "Request without getting response");
+                       p2p_dbg(p2p, "Timeout on sending GO Negotiation Request without getting response");
                        p2p_go_neg_failed(p2p, p2p->go_neg_peer, -1);
                        return;
                }
@@ -3387,23 +3255,18 @@ static void p2p_timeout_wait_peer_idle(struct p2p_data *p2p)
        struct p2p_device *dev = p2p->go_neg_peer;
 
        if (dev == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unknown GO Neg peer - stop GO Neg wait");
+               p2p_dbg(p2p, "Unknown GO Neg peer - stop GO Neg wait");
                return;
        }
 
        dev->wait_count++;
        if (dev->wait_count >= 120) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Timeout on waiting peer to become ready for GO "
-                       "Negotiation");
+               p2p_dbg(p2p, "Timeout on waiting peer to become ready for GO Negotiation");
                p2p_go_neg_failed(p2p, dev, -1);
                return;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Go to Listen state while waiting for the peer to become "
-               "ready for GO Negotiation");
+       p2p_dbg(p2p, "Go to Listen state while waiting for the peer to become ready for GO Negotiation");
        p2p_set_state(p2p, P2P_WAIT_PEER_CONNECT);
        p2p_listen_in_find(p2p, 0);
 }
@@ -3411,8 +3274,7 @@ static void p2p_timeout_wait_peer_idle(struct p2p_data *p2p)
 
 static void p2p_timeout_sd_during_find(struct p2p_data *p2p)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Service Discovery Query timeout");
+       p2p_dbg(p2p, "Service Discovery Query timeout");
        if (p2p->sd_peer) {
                p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
                p2p->sd_peer->flags &= ~P2P_DEV_SD_SCHEDULE;
@@ -3424,8 +3286,7 @@ static void p2p_timeout_sd_during_find(struct p2p_data *p2p)
 
 static void p2p_timeout_prov_disc_during_find(struct p2p_data *p2p)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Provision Discovery Request timeout");
+       p2p_dbg(p2p, "Provision Discovery Request timeout");
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
        p2p_continue_find(p2p);
 }
@@ -3443,8 +3304,7 @@ static void p2p_timeout_prov_disc_req(struct p2p_data *p2p)
        if (!p2p->user_initiated_pd)
                return;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: User initiated Provision Discovery Request timeout");
+       p2p_dbg(p2p, "User initiated Provision Discovery Request timeout");
 
        if (p2p->pd_retries) {
                p2p->pd_retries--;
@@ -3482,8 +3342,7 @@ static void p2p_timeout_invite(struct p2p_data *p2p)
                 * Better remain on operating channel instead of listen channel
                 * when running a group.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Inviting in "
-                       "active GO role - wait on operating channel");
+               p2p_dbg(p2p, "Inviting in active GO role - wait on operating channel");
                p2p_set_timeout(p2p, 0, 100000);
                return;
        }
@@ -3499,8 +3358,7 @@ static void p2p_timeout_invite_listen(struct p2p_data *p2p)
                                p2p->invite_go_dev_addr);
        } else {
                if (p2p->invite_peer) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Invitation Request retry limit reached");
+                       p2p_dbg(p2p, "Invitation Request retry limit reached");
                        if (p2p->cfg->invitation_result)
                                p2p->cfg->invitation_result(
                                        p2p->cfg->cb_ctx, -1, NULL, NULL,
@@ -3515,8 +3373,7 @@ static void p2p_state_timeout(void *eloop_ctx, void *timeout_ctx)
 {
        struct p2p_data *p2p = eloop_ctx;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Timeout (state=%s)",
-               p2p_state_txt(p2p->state));
+       p2p_dbg(p2p, "Timeout (state=%s)", p2p_state_txt(p2p->state));
 
        p2p->in_listen = 0;
 
@@ -3531,8 +3388,7 @@ static void p2p_state_timeout(void *eloop_ctx, void *timeout_ctx)
                if (p2p->pending_action_state == P2P_PENDING_PD)
                        p2p_timeout_prov_disc_req(p2p);
                if (p2p->search_delay && !p2p->in_search_delay) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Delay "
-                               "search operation by %u ms",
+                       p2p_dbg(p2p, "Delay search operation by %u ms",
                                p2p->search_delay);
                        p2p->in_search_delay = 1;
                        p2p_set_timeout(p2p, p2p->search_delay / 1000,
@@ -3556,9 +3412,7 @@ static void p2p_state_timeout(void *eloop_ctx, void *timeout_ctx)
                        p2p_timeout_prov_disc_req(p2p);
 
                if (p2p->ext_listen_only) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Extended Listen Timing - Listen State "
-                               "completed");
+                       p2p_dbg(p2p, "Extended Listen Timing - Listen State completed");
                        p2p->ext_listen_only = 0;
                        p2p_set_state(p2p, P2P_IDLE);
                }
@@ -3596,11 +3450,10 @@ int p2p_reject(struct p2p_data *p2p, const u8 *peer_addr)
        struct p2p_device *dev;
 
        dev = p2p_get_device(p2p, peer_addr);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Local request to reject "
-               "connection attempts by peer " MACSTR, MAC2STR(peer_addr));
+       p2p_dbg(p2p, "Local request to reject connection attempts by peer "
+               MACSTR, MAC2STR(peer_addr));
        if (dev == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
-                       " unknown", MAC2STR(peer_addr));
+               p2p_dbg(p2p, "Peer " MACSTR " unknown", MAC2STR(peer_addr));
                return -1;
        }
        dev->status = P2P_SC_FAIL_REJECTED_BY_USER;
@@ -3801,12 +3654,10 @@ int p2p_peer_known(struct p2p_data *p2p, const u8 *addr)
 void p2p_set_client_discoverability(struct p2p_data *p2p, int enabled)
 {
        if (enabled) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Client "
-                       "discoverability enabled");
+               p2p_dbg(p2p, "Client discoverability enabled");
                p2p->dev_capab |= P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY;
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Client "
-                       "discoverability disabled");
+               p2p_dbg(p2p, "Client discoverability disabled");
                p2p->dev_capab &= ~P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY;
        }
 }
@@ -3855,9 +3706,9 @@ int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr,
 {
        struct wpabuf *req;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send Presence Request to "
-               "GO " MACSTR " (own interface " MACSTR ") freq=%u dur1=%u "
-               "int1=%u dur2=%u int2=%u",
+       p2p_dbg(p2p, "Send Presence Request to GO " MACSTR
+               " (own interface " MACSTR ") freq=%u dur1=%u int1=%u "
+               "dur2=%u int2=%u",
                MAC2STR(go_interface_addr), MAC2STR(own_interface_addr),
                freq, duration1, interval1, duration2, interval2);
 
@@ -3870,8 +3721,7 @@ int p2p_presence_req(struct p2p_data *p2p, const u8 *go_interface_addr,
        if (p2p_send_action(p2p, freq, go_interface_addr, own_interface_addr,
                            go_interface_addr,
                            wpabuf_head(req), wpabuf_len(req), 200) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
        wpabuf_free(req);
 
@@ -3917,8 +3767,7 @@ static void p2p_process_presence_req(struct p2p_data *p2p, const u8 *da,
        u8 noa[50];
        int noa_len;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received P2P Action - P2P Presence Request");
+       p2p_dbg(p2p, "Received P2P Action - P2P Presence Request");
 
        for (g = 0; g < p2p->num_groups; g++) {
                if (os_memcmp(da, p2p_group_get_interface_addr(p2p->groups[g]),
@@ -3928,23 +3777,20 @@ static void p2p_process_presence_req(struct p2p_data *p2p, const u8 *da,
                }
        }
        if (group == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore P2P Presence Request for unknown group "
+               p2p_dbg(p2p, "Ignore P2P Presence Request for unknown group "
                        MACSTR, MAC2STR(da));
                return;
        }
 
        if (p2p_parse(data, len, &msg) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to parse P2P Presence Request");
+               p2p_dbg(p2p, "Failed to parse P2P Presence Request");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
        parsed = 1;
 
        if (msg.noa == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No NoA attribute in P2P Presence Request");
+               p2p_dbg(p2p, "No NoA attribute in P2P Presence Request");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
@@ -3968,8 +3814,7 @@ fail:
        p2p->pending_action_state = P2P_NO_PENDING_ACTION;
        if (p2p_send_action(p2p, rx_freq, sa, da, da,
                            wpabuf_head(resp), wpabuf_len(resp), 200) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
        wpabuf_free(resp);
 }
@@ -3980,33 +3825,27 @@ static void p2p_process_presence_resp(struct p2p_data *p2p, const u8 *da,
 {
        struct p2p_message msg;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received P2P Action - P2P Presence Response");
+       p2p_dbg(p2p, "Received P2P Action - P2P Presence Response");
 
        if (p2p_parse(data, len, &msg) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to parse P2P Presence Response");
+               p2p_dbg(p2p, "Failed to parse P2P Presence Response");
                return;
        }
 
        if (msg.status == NULL || msg.noa == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Status or NoA attribute in P2P Presence "
-                       "Response");
+               p2p_dbg(p2p, "No Status or NoA attribute in P2P Presence Response");
                p2p_parse_free(&msg);
                return;
        }
 
        if (*msg.status) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: P2P Presence Request was rejected: status %u",
+               p2p_dbg(p2p, "P2P Presence Request was rejected: status %u",
                        *msg.status);
                p2p_parse_free(&msg);
                return;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: P2P Presence Request was accepted");
+       p2p_dbg(p2p, "P2P Presence Request was accepted");
        wpa_hexdump(MSG_DEBUG, "P2P: P2P Presence Response - NoA",
                    msg.noa, msg.noa_len);
        /* TODO: process NoA */
@@ -4032,25 +3871,20 @@ static void p2p_ext_listen_timeout(void *eloop_ctx, void *timeout_ctx)
                 * running at an inconvenient time. As a workaround, allow new
                 * Extended Listen operation to be started.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Previous "
-                       "Extended Listen operation had not been completed - "
-                       "try again");
+               p2p_dbg(p2p, "Previous Extended Listen operation had not been completed - try again");
                p2p->ext_listen_only = 0;
                p2p_set_state(p2p, P2P_IDLE);
        }
 
        if (p2p->state != P2P_IDLE) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Skip Extended "
-                       "Listen timeout in active state (%s)",
-                       p2p_state_txt(p2p->state));
+               p2p_dbg(p2p, "Skip Extended Listen timeout in active state (%s)", p2p_state_txt(p2p->state));
                return;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Extended Listen timeout");
+       p2p_dbg(p2p, "Extended Listen timeout");
        p2p->ext_listen_only = 1;
        if (p2p_listen(p2p, p2p->ext_listen_period) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Failed to start "
-                       "Listen state for Extended Listen Timing");
+               p2p_dbg(p2p, "Failed to start Listen state for Extended Listen Timing");
                p2p->ext_listen_only = 0;
        }
 }
@@ -4061,25 +3895,22 @@ int p2p_ext_listen(struct p2p_data *p2p, unsigned int period,
 {
        if (period > 65535 || interval > 65535 || period > interval ||
            (period == 0 && interval > 0) || (period > 0 && interval == 0)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid Extended Listen Timing request: "
-                       "period=%u interval=%u", period, interval);
+               p2p_dbg(p2p, "Invalid Extended Listen Timing request: period=%u interval=%u",
+                       period, interval);
                return -1;
        }
 
        eloop_cancel_timeout(p2p_ext_listen_timeout, p2p, NULL);
 
        if (interval == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Disabling Extended Listen Timing");
+               p2p_dbg(p2p, "Disabling Extended Listen Timing");
                p2p->ext_listen_period = 0;
                p2p->ext_listen_interval = 0;
                return 0;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Enabling Extended Listen Timing: period %u msec, "
-               "interval %u msec", period, interval);
+       p2p_dbg(p2p, "Enabling Extended Listen Timing: period %u msec, interval %u msec",
+               period, interval);
        p2p->ext_listen_period = period;
        p2p->ext_listen_interval = interval;
        p2p->ext_listen_interval_sec = interval / 1000;
@@ -4107,8 +3938,7 @@ void p2p_deauth_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
        if (msg.minor_reason_code == NULL)
                return;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
-               "P2P: Deauthentication notification BSSID " MACSTR
+       p2p_dbg(p2p, "Deauthentication notification BSSID " MACSTR
                " reason_code=%u minor_reason_code=%u",
                MAC2STR(bssid), reason_code, *msg.minor_reason_code);
 
@@ -4130,8 +3960,7 @@ void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
        if (msg.minor_reason_code == NULL)
                return;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
-               "P2P: Disassociation notification BSSID " MACSTR
+       p2p_dbg(p2p, "Disassociation notification BSSID " MACSTR
                " reason_code=%u minor_reason_code=%u",
                MAC2STR(bssid), reason_code, *msg.minor_reason_code);
 
@@ -4142,12 +3971,10 @@ void p2p_disassoc_notif(struct p2p_data *p2p, const u8 *bssid, u16 reason_code,
 void p2p_set_managed_oper(struct p2p_data *p2p, int enabled)
 {
        if (enabled) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Managed P2P "
-                       "Device operations enabled");
+               p2p_dbg(p2p, "Managed P2P Device operations enabled");
                p2p->dev_capab |= P2P_DEV_CAPAB_INFRA_MANAGED;
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Managed P2P "
-                       "Device operations disabled");
+               p2p_dbg(p2p, "Managed P2P Device operations disabled");
                p2p->dev_capab &= ~P2P_DEV_CAPAB_INFRA_MANAGED;
        }
 }
@@ -4158,8 +3985,8 @@ int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel)
        if (p2p_channel_to_freq(reg_class, channel) < 0)
                return -1;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Set Listen channel: "
-               "reg_class %u channel %u", reg_class, channel);
+       p2p_dbg(p2p, "Set Listen channel: reg_class %u channel %u",
+               reg_class, channel);
        p2p->cfg->reg_class = reg_class;
        p2p->cfg->channel = channel;
 
@@ -4169,7 +3996,7 @@ int p2p_set_listen_channel(struct p2p_data *p2p, u8 reg_class, u8 channel)
 
 int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len)
 {
-       wpa_hexdump_ascii(MSG_DEBUG, "P2P: New SSID postfix", postfix, len);
+       p2p_dbg(p2p, "New SSID postfix: %s", wpa_ssid_txt(postfix, len));
        if (postfix == NULL) {
                p2p->cfg->ssid_postfix_len = 0;
                return 0;
@@ -4188,8 +4015,8 @@ int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel,
        if (p2p_channel_to_freq(op_reg_class, op_channel) < 0)
                return -1;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, "P2P: Set Operating channel: "
-               "reg_class %u channel %u", op_reg_class, op_channel);
+       p2p_dbg(p2p, "Set Operating channel: reg_class %u channel %u",
+               op_reg_class, op_channel);
        p2p->cfg->op_reg_class = op_reg_class;
        p2p->cfg->op_channel = op_channel;
        p2p->cfg->cfg_op_channel = cfg_op_channel;
@@ -4245,18 +4072,16 @@ void p2p_set_peer_filter(struct p2p_data *p2p, const u8 *addr)
 {
        os_memcpy(p2p->peer_filter, addr, ETH_ALEN);
        if (is_zero_ether_addr(p2p->peer_filter))
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Disable peer "
-                       "filter");
+               p2p_dbg(p2p, "Disable peer filter");
        else
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Enable peer "
-                       "filter for " MACSTR, MAC2STR(p2p->peer_filter));
+               p2p_dbg(p2p, "Enable peer filter for " MACSTR,
+                       MAC2STR(p2p->peer_filter));
 }
 
 
 void p2p_set_cross_connect(struct p2p_data *p2p, int enabled)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Cross connection %s",
-               enabled ? "enabled" : "disabled");
+       p2p_dbg(p2p, "Cross connection %s", enabled ? "enabled" : "disabled");
        if (p2p->cross_connect == enabled)
                return;
        p2p->cross_connect = enabled;
@@ -4277,7 +4102,7 @@ int p2p_get_oper_freq(struct p2p_data *p2p, const u8 *iface_addr)
 
 void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Intra BSS distribution %s",
+       p2p_dbg(p2p, "Intra BSS distribution %s",
                enabled ? "enabled" : "disabled");
        p2p->cfg->p2p_intra_bss = enabled;
 }
@@ -4285,7 +4110,7 @@ void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled)
 
 void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Update channel list");
+       p2p_dbg(p2p, "Update channel list");
        os_memcpy(&p2p->cfg->channels, chan, sizeof(struct p2p_channels));
 }
 
@@ -4295,11 +4120,9 @@ int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
                    size_t len, unsigned int wait_time)
 {
        if (p2p->p2p_scan_running) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Delay Action "
-                       "frame TX until p2p_scan completes");
+               p2p_dbg(p2p, "Delay Action frame TX until p2p_scan completes");
                if (p2p->after_scan_tx) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Dropped "
-                               "previous pending Action frame TX");
+                       p2p_dbg(p2p, "Dropped previous pending Action frame TX");
                        os_free(p2p->after_scan_tx);
                }
                p2p->after_scan_tx = os_malloc(sizeof(*p2p->after_scan_tx) +
@@ -4324,8 +4147,8 @@ int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
 void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5,
                           int freq_overall)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Best channel: 2.4 GHz: %d,"
-               "  5 GHz: %d,  overall: %d", freq_24, freq_5, freq_overall);
+       p2p_dbg(p2p, "Best channel: 2.4 GHz: %d,  5 GHz: %d,  overall: %d",
+               freq_24, freq_5, freq_overall);
        p2p->best_freq_24 = freq_24;
        p2p->best_freq_5 = freq_5;
        p2p->best_freq_overall = freq_overall;
@@ -4334,8 +4157,7 @@ void p2p_set_best_channels(struct p2p_data *p2p, int freq_24, int freq_5,
 
 void p2p_set_own_freq_preference(struct p2p_data *p2p, int freq)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Own frequency preference: "
-               "%d MHz", freq);
+       p2p_dbg(p2p, "Own frequency preference: %d MHz", freq);
        p2p->own_freq_preference = freq;
 }
 
@@ -4560,9 +4382,56 @@ int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int,
        p2p->min_disc_int = min_disc_int;
        p2p->max_disc_int = max_disc_int;
        p2p->max_disc_tu = max_disc_tu;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Set discoverable interval: "
-               "min=%d max=%d max_tu=%d", min_disc_int, max_disc_int,
-               max_disc_tu);
+       p2p_dbg(p2p, "Set discoverable interval: min=%d max=%d max_tu=%d",
+               min_disc_int, max_disc_int, max_disc_tu);
 
        return 0;
 }
+
+
+void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...)
+{
+       va_list ap;
+       char buf[500];
+
+       if (!p2p->cfg->debug_print)
+               return;
+
+       va_start(ap, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
+       buf[sizeof(buf) - 1] = '\0';
+       va_end(ap);
+       p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_DEBUG, buf);
+}
+
+
+void p2p_info(struct p2p_data *p2p, const char *fmt, ...)
+{
+       va_list ap;
+       char buf[500];
+
+       if (!p2p->cfg->debug_print)
+               return;
+
+       va_start(ap, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
+       buf[sizeof(buf) - 1] = '\0';
+       va_end(ap);
+       p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_INFO, buf);
+}
+
+
+void p2p_err(struct p2p_data *p2p, const char *fmt, ...)
+{
+       va_list ap;
+       char buf[500];
+
+       if (!p2p->cfg->debug_print)
+               return;
+
+       va_start(ap, fmt);
+       vsnprintf(buf, sizeof(buf), fmt, ap);
+       buf[sizeof(buf) - 1] = '\0';
+       va_end(ap);
+       p2p->cfg->debug_print(p2p->cfg->cb_ctx, MSG_ERROR, buf);
+}
index b197893..499b62e 100644 (file)
@@ -384,14 +384,17 @@ struct p2p_config {
 #endif
 
        /**
-        * msg_ctx - Context to use with wpa_msg() calls
+        * cb_ctx - Context to use with callback functions
         */
-       void *msg_ctx;
+       void *cb_ctx;
 
        /**
-        * cb_ctx - Context to use with callback functions
+        * debug_print - Debug print
+        * @ctx: Callback context from cb_ctx
+        * @level: Debug verbosity level (MSG_*)
+        * @msg: Debug message
         */
-       void *cb_ctx;
+       void (*debug_print)(void *ctx, int level, const char *msg);
 
 
        /* Callbacks to request lower layer driver operations */
@@ -558,6 +561,12 @@ struct p2p_config {
        void (*dev_lost)(void *ctx, const u8 *dev_addr);
 
        /**
+        * find_stopped - Notification of a p2p_find operation stopping
+        * @ctx: Callback context from cb_ctx
+        */
+       void (*find_stopped)(void *ctx);
+
+       /**
         * go_neg_req_rx - Notification of a receive GO Negotiation Request
         * @ctx: Callback context from cb_ctx
         * @src: Source address of the message triggering this notification
index c976b7c..76d01cf 100644 (file)
@@ -42,8 +42,7 @@ static struct wpabuf * p2p_build_dev_disc_req(struct p2p_data *p2p,
 
 void p2p_dev_disc_req_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Device Discoverability Request TX callback: success=%d",
+       p2p_dbg(p2p, "Device Discoverability Request TX callback: success=%d",
                success);
 
        if (!success) {
@@ -56,9 +55,7 @@ void p2p_dev_disc_req_cb(struct p2p_data *p2p, int success)
                return;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO acknowledged Device Discoverability Request - wait "
-               "for response");
+       p2p_dbg(p2p, "GO acknowledged Device Discoverability Request - wait for response");
        /*
         * TODO: is the remain-on-channel from Action frame TX long enough for
         * most cases or should we try to increase its duration and/or start
@@ -74,9 +71,7 @@ int p2p_send_dev_disc_req(struct p2p_data *p2p, struct p2p_device *dev)
 
        go = p2p_get_device(p2p, dev->member_in_go_dev);
        if (go == NULL || dev->oper_freq <= 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Could not find peer entry for GO and frequency "
-                       "to send Device Discoverability Request");
+               p2p_dbg(p2p, "Could not find peer entry for GO and frequency to send Device Discoverability Request");
                return -1;
        }
 
@@ -84,8 +79,7 @@ int p2p_send_dev_disc_req(struct p2p_data *p2p, struct p2p_device *dev)
        if (req == NULL)
                return -1;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending Device Discoverability Request to GO " MACSTR
+       p2p_dbg(p2p, "Sending Device Discoverability Request to GO " MACSTR
                " for client " MACSTR,
                MAC2STR(go->info.p2p_device_addr),
                MAC2STR(dev->info.p2p_device_addr));
@@ -97,8 +91,7 @@ int p2p_send_dev_disc_req(struct p2p_data *p2p, struct p2p_device *dev)
        if (p2p_send_action(p2p, dev->oper_freq, go->info.p2p_device_addr,
                            p2p->cfg->dev_addr, go->info.p2p_device_addr,
                            wpabuf_head(req), wpabuf_len(req), 1000) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
                wpabuf_free(req);
                /* TODO: how to recover from failure? */
                return -1;
@@ -131,8 +124,7 @@ static struct wpabuf * p2p_build_dev_disc_resp(u8 dialog_token, u8 status)
 
 void p2p_dev_disc_resp_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Device Discoverability Response TX callback: success=%d",
+       p2p_dbg(p2p, "Device Discoverability Response TX callback: success=%d",
                success);
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
 }
@@ -147,8 +139,7 @@ static void p2p_send_dev_disc_resp(struct p2p_data *p2p, u8 dialog_token,
        if (resp == NULL)
                return;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending Device Discoverability Response to " MACSTR
+       p2p_dbg(p2p, "Sending Device Discoverability Response to " MACSTR
                " (status %u freq %d)",
                MAC2STR(addr), status, freq);
 
@@ -156,8 +147,7 @@ static void p2p_send_dev_disc_resp(struct p2p_data *p2p, u8 dialog_token,
        if (p2p_send_action(p2p, freq, addr, 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");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
 
        wpabuf_free(resp);
@@ -170,17 +160,14 @@ void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa,
        struct p2p_message msg;
        size_t g;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received Device Discoverability Request from " MACSTR
+       p2p_dbg(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_dbg(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);
@@ -188,9 +175,7 @@ void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa,
        }
 
        if (msg.device_id == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: P2P Device ID attribute missing from Device "
-                       "Discoverability Request");
+               p2p_dbg(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);
@@ -200,9 +185,7 @@ void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa,
        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_dbg(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
@@ -217,9 +200,7 @@ void p2p_process_dev_disc_req(struct p2p_data *p2p, const u8 *sa,
                }
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Requested client "
-               "was not found in any group or did not support client "
-               "discoverability");
+       p2p_dbg(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);
@@ -233,15 +214,13 @@ void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
        struct p2p_device *go;
        u8 status;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received Device Discoverability Response from " MACSTR,
+       p2p_dbg(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");
+               p2p_dbg(p2p, "Ignore unexpected Device Discoverability Response");
                return;
        }
 
@@ -254,9 +233,7 @@ void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
        }
 
        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)",
+               p2p_dbg(p2p, "Ignore Device Discoverability Response with unexpected dialog token %u (expected %u)",
                        msg.dialog_token, go->dialog_token);
                p2p_parse_free(&msg);
                return;
@@ -265,17 +242,14 @@ void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
        status = *msg.status;
        p2p_parse_free(&msg);
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Device Discoverability Response status %u", status);
+       p2p_dbg(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");
+               p2p_dbg(p2p, "No pending operation with the client discoverability peer anymore");
                return;
        }
 
@@ -284,8 +258,7 @@ void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
                 * 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");
+               p2p_dbg(p2p, "Client discoverability request succeeded");
                if (p2p->state == P2P_CONNECT) {
                        /*
                         * Change state to force the timeout to start in
@@ -301,8 +274,7 @@ void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
                 * Client discoverability request failed; try to connect from
                 * timeout.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Client discoverability request failed");
+               p2p_dbg(p2p, "Client discoverability request failed");
                p2p_set_timeout(p2p, 0, 500000);
        }
 
@@ -311,14 +283,12 @@ void p2p_process_dev_disc_resp(struct p2p_data *p2p, const u8 *sa,
 
 void p2p_go_disc_req_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Discoverability Request TX callback: success=%d",
+       p2p_dbg(p2p, "GO Discoverability Request TX callback: success=%d",
                success);
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
 
        if (p2p->pending_dev_disc_dialog_token == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending Device "
-                       "Discoverability Request");
+               p2p_dbg(p2p, "No pending Device Discoverability Request");
                return;
        }
 
@@ -338,9 +308,7 @@ void p2p_process_go_disc_req(struct p2p_data *p2p, const u8 *da, const u8 *sa,
        unsigned int tu;
        struct wpabuf *ies;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received GO Discoverability Request - remain awake for "
-               "100 TU");
+       p2p_dbg(p2p, "Received GO Discoverability Request - remain awake for 100 TU");
 
        ies = p2p_build_probe_resp_ies(p2p);
        if (ies == NULL)
@@ -351,9 +319,7 @@ void p2p_process_go_disc_req(struct p2p_data *p2p, const u8 *da, const u8 *sa,
        tu = 100;
        if (p2p->cfg->start_listen(p2p->cfg->cb_ctx, rx_freq, 1024 * tu / 1000,
                    ies) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to start listen mode for client "
-                       "discoverability");
+               p2p_dbg(p2p, "Failed to start listen mode for client discoverability");
        }
        wpabuf_free(ies);
 }
index c7cf205..4fba550 100644 (file)
@@ -49,8 +49,7 @@ int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own,
        os_memcpy(dev->country, pos, 3);
        wpa_hexdump_ascii(MSG_DEBUG, "P2P: Peer country", pos, 3);
        if (pos[2] != 0x04 && os_memcmp(pos, p2p->cfg->country, 2) != 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
-                       "P2P: Mismatching country (ours=%c%c peer's=%c%c)",
+               p2p_info(p2p, "Mismatching country (ours=%c%c peer's=%c%c)",
                        p2p->cfg->country[0], p2p->cfg->country[1],
                        pos[0], pos[1]);
                return -1;
@@ -61,8 +60,7 @@ int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own,
                struct p2p_reg_class *cl = &ch->reg_class[ch->reg_classes];
                cl->reg_class = *pos++;
                if (pos + 1 + pos[0] > end) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
-                               "P2P: Invalid peer Channel List");
+                       p2p_info(p2p, "Invalid peer Channel List");
                        return -1;
                }
                channels = *pos++;
@@ -76,14 +74,12 @@ int p2p_peer_channels_check(struct p2p_data *p2p, struct p2p_channels *own,
        }
 
        p2p_channels_intersect(own, &dev->channels, &intersection);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Own reg_classes %d "
-               "peer reg_classes %d intersection reg_classes %d",
+       p2p_dbg(p2p, "Own reg_classes %d peer reg_classes %d intersection reg_classes %d",
                (int) own->reg_classes,
                (int) dev->channels.reg_classes,
                (int) intersection.reg_classes);
        if (intersection.reg_classes == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_INFO,
-                       "P2P: No common channels found");
+               p2p_info(p2p, "No common channels found");
                return -1;
        }
        return 0;
@@ -194,8 +190,7 @@ int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
 
        if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) {
                u16 config_method;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Use PD-before-GO-Neg workaround for " MACSTR,
+               p2p_dbg(p2p, "Use PD-before-GO-Neg workaround for " MACSTR,
                        MAC2STR(dev->info.p2p_device_addr));
                if (dev->wps_method == WPS_PIN_DISPLAY)
                        config_method = WPS_CONFIG_KEYPAD;
@@ -211,9 +206,8 @@ int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
 
        freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
        if (freq <= 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Listen/Operating frequency known for the "
-                       "peer " MACSTR " to send GO Negotiation Request",
+               p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
+                       MACSTR " to send GO Negotiation Request",
                        MAC2STR(dev->info.p2p_device_addr));
                return -1;
        }
@@ -221,8 +215,7 @@ int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
        req = p2p_build_go_neg_req(p2p, dev);
        if (req == NULL)
                return -1;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending GO Negotiation Request");
+       p2p_dbg(p2p, "Sending GO Negotiation Request");
        p2p_set_state(p2p, P2P_CONNECT);
        p2p->pending_action_state = P2P_PENDING_GO_NEG_REQUEST;
        p2p->go_neg_peer = dev;
@@ -231,8 +224,7 @@ int p2p_connect_send(struct p2p_data *p2p, struct p2p_device *dev)
        if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
                            p2p->cfg->dev_addr, dev->info.p2p_device_addr,
                            wpabuf_head(req), wpabuf_len(req), 500) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
                /* Use P2P find to recover and retry */
                p2p_set_timeout(p2p, 0, 0);
        } else
@@ -254,8 +246,7 @@ static struct wpabuf * p2p_build_go_neg_resp(struct p2p_data *p2p,
        u8 group_capab;
        size_t extra = 0;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Building GO Negotiation Response");
+       p2p_dbg(p2p, "Building GO Negotiation Response");
 
 #ifdef CONFIG_WIFI_DISPLAY
        if (p2p->wfd_ie_go_neg)
@@ -289,8 +280,7 @@ static struct wpabuf * p2p_build_go_neg_resp(struct p2p_data *p2p,
        p2p_buf_add_go_intent(buf, (p2p->go_intent << 1) | tie_breaker);
        p2p_buf_add_config_timeout(buf, p2p->go_timeout, p2p->client_timeout);
        if (peer && peer->go_state == REMOTE_GO) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Omit Operating "
-                       "Channel attribute");
+               p2p_dbg(p2p, "Omit Operating Channel attribute");
        } else {
                p2p_buf_add_operating_channel(buf, p2p->cfg->country,
                                              p2p->op_reg_class,
@@ -354,9 +344,8 @@ void p2p_reselect_channel(struct p2p_data *p2p,
            p2p_freq_to_channel(p2p->own_freq_preference,
                                &op_reg_class, &op_channel) == 0 &&
            p2p_channels_includes(intersection, op_reg_class, op_channel)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick own channel "
-                       "preference (reg_class %u channel %u) from "
-                       "intersection", op_reg_class, op_channel);
+               p2p_dbg(p2p, "Pick own channel preference (reg_class %u channel %u) from intersection",
+                       op_reg_class, op_channel);
                p2p->op_reg_class = op_reg_class;
                p2p->op_channel = op_channel;
                return;
@@ -366,8 +355,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
            p2p_freq_to_channel(p2p->best_freq_overall,
                                &op_reg_class, &op_channel) == 0 &&
            p2p_channels_includes(intersection, op_reg_class, op_channel)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best overall "
-                       "channel (reg_class %u channel %u) from intersection",
+               p2p_dbg(p2p, "Pick best overall channel (reg_class %u channel %u) from intersection",
                        op_reg_class, op_channel);
                p2p->op_reg_class = op_reg_class;
                p2p->op_channel = op_channel;
@@ -382,8 +370,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
            p2p_freq_to_channel(p2p->best_freq_5,
                                &op_reg_class, &op_channel) == 0 &&
            p2p_channels_includes(intersection, op_reg_class, op_channel)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best 5 GHz "
-                       "channel (reg_class %u channel %u) from intersection",
+               p2p_dbg(p2p, "Pick best 5 GHz channel (reg_class %u channel %u) from intersection",
                        op_reg_class, op_channel);
                p2p->op_reg_class = op_reg_class;
                p2p->op_channel = op_channel;
@@ -396,8 +383,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
            p2p_freq_to_channel(p2p->best_freq_24,
                                &op_reg_class, &op_channel) == 0 &&
            p2p_channels_includes(intersection, op_reg_class, op_channel)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick best 2.4 GHz "
-                       "channel (reg_class %u channel %u) from intersection",
+               p2p_dbg(p2p, "Pick best 2.4 GHz channel (reg_class %u channel %u) from intersection",
                        op_reg_class, op_channel);
                p2p->op_reg_class = op_reg_class;
                p2p->op_channel = op_channel;
@@ -411,9 +397,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
                                          p2p->cfg->pref_chan[i].chan)) {
                        p2p->op_reg_class = p2p->cfg->pref_chan[i].op_class;
                        p2p->op_channel = p2p->cfg->pref_chan[i].chan;
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick "
-                               "highest preferred chnnel (op_class %u "
-                               "channel %u) from intersection",
+                       p2p_dbg(p2p, "Pick highest preferred channel (op_class %u channel %u) from intersection",
                                p2p->op_reg_class, p2p->op_channel);
                        return;
                }
@@ -424,9 +408,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
                struct p2p_reg_class *c = &intersection->reg_class[i];
                if (c->reg_class == 116 || c->reg_class == 117 ||
                    c->reg_class == 126 || c->reg_class == 127) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Pick possible HT40 channel (reg_class "
-                               "%u channel %u) from intersection",
+                       p2p_dbg(p2p, "Pick possible HT40 channel (reg_class %u channel %u) from intersection",
                                c->reg_class, c->channel[0]);
                        p2p->op_reg_class = c->reg_class;
                        p2p->op_channel = c->channel[0];
@@ -441,9 +423,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
         */
        if (p2p_channels_includes(intersection, p2p->op_reg_class,
                                  p2p->op_channel)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Using original operating class and channel "
-                       "(op_class %u channel %u) from intersection",
+               p2p_dbg(p2p, "Using original operating class and channel (op_class %u channel %u) from intersection",
                        p2p->op_reg_class, p2p->op_channel);
                return;
        }
@@ -453,8 +433,7 @@ void p2p_reselect_channel(struct p2p_data *p2p,
         * no better options seems to be available.
         */
        cl = &intersection->reg_class[0];
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Pick another channel "
-               "(reg_class %u channel %u) from intersection",
+       p2p_dbg(p2p, "Pick another channel (reg_class %u channel %u) from intersection",
                cl->reg_class, cl->channel[0]);
        p2p->op_reg_class = cl->reg_class;
        p2p->op_channel = cl->channel[0];
@@ -471,15 +450,14 @@ static int p2p_go_select_channel(struct p2p_data *p2p, struct p2p_device *dev,
        if (intersection.reg_classes == 0 ||
            intersection.reg_class[0].channels == 0) {
                *status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No common channels found");
+               p2p_dbg(p2p, "No common channels found");
                return -1;
        }
 
        for (i = 0; i < intersection.reg_classes; i++) {
                struct p2p_reg_class *c;
                c = &intersection.reg_class[i];
-               wpa_printf(MSG_DEBUG, "P2P: reg_class %u", c->reg_class);
+               p2p_dbg(p2p, "reg_class %u", c->reg_class);
                wpa_hexdump(MSG_DEBUG, "P2P: channels",
                            c->channel, c->channels);
        }
@@ -488,20 +466,16 @@ static int p2p_go_select_channel(struct p2p_data *p2p, struct p2p_device *dev,
                                   p2p->op_channel)) {
                if (dev->flags & P2P_DEV_FORCE_FREQ) {
                        *status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer does "
-                               "not support the forced channel");
+                       p2p_dbg(p2p, "Peer does not support the forced channel");
                        return -1;
                }
 
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Selected operating "
-                       "channel (op_class %u channel %u) not acceptable to "
-                       "the peer", p2p->op_reg_class, p2p->op_channel);
+               p2p_dbg(p2p, "Selected operating channel (op_class %u channel %u) not acceptable to the peer",
+                       p2p->op_reg_class, p2p->op_channel);
                p2p_reselect_channel(p2p, &intersection);
        } else if (!(dev->flags & P2P_DEV_FORCE_FREQ) &&
                   !p2p->cfg->cfg_op_channel) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Try to optimize "
-                       "channel selection with peer information received; "
-                       "previously selected op_class %u channel %u",
+               p2p_dbg(p2p, "Try to optimize 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);
        }
@@ -525,17 +499,14 @@ void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
        int tie_breaker = 0;
        int freq;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received GO Negotiation Request from " MACSTR
-               "(freq=%d)", MAC2STR(sa), rx_freq);
+       p2p_dbg(p2p, "Received GO Negotiation Request from " MACSTR "(freq=%d)",
+               MAC2STR(sa), rx_freq);
 
        if (p2p_parse(data, len, &msg))
                return;
 
        if (!msg.capability) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Capability attribute missing from GO "
-                       "Negotiation Request");
+               p2p_dbg(p2p, "Mandatory Capability attribute missing from GO Negotiation Request");
 #ifdef CONFIG_P2P_STRICT
                goto fail;
 #endif /* CONFIG_P2P_STRICT */
@@ -544,53 +515,42 @@ void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
        if (msg.go_intent)
                tie_breaker = *msg.go_intent & 0x01;
        else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory GO Intent attribute missing from GO "
-                       "Negotiation Request");
+               p2p_dbg(p2p, "Mandatory GO Intent attribute missing from GO Negotiation Request");
 #ifdef CONFIG_P2P_STRICT
                goto fail;
 #endif /* CONFIG_P2P_STRICT */
        }
 
        if (!msg.config_timeout) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Configuration Timeout attribute "
-                       "missing from GO Negotiation Request");
+               p2p_dbg(p2p, "Mandatory Configuration Timeout attribute missing from GO Negotiation Request");
 #ifdef CONFIG_P2P_STRICT
                goto fail;
 #endif /* CONFIG_P2P_STRICT */
        }
 
        if (!msg.listen_channel) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Listen Channel attribute received");
+               p2p_dbg(p2p, "No Listen Channel attribute received");
                goto fail;
        }
        if (!msg.operating_channel) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Operating Channel attribute received");
+               p2p_dbg(p2p, "No Operating Channel attribute received");
                goto fail;
        }
        if (!msg.channel_list) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Channel List attribute received");
+               p2p_dbg(p2p, "No Channel List attribute received");
                goto fail;
        }
        if (!msg.intended_addr) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Intended P2P Interface Address attribute "
-                       "received");
+               p2p_dbg(p2p, "No Intended P2P Interface Address attribute received");
                goto fail;
        }
        if (!msg.p2p_device_info) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No P2P Device Info attribute received");
+               p2p_dbg(p2p, "No P2P Device Info attribute received");
                goto fail;
        }
 
        if (os_memcmp(msg.p2p_device_addr, sa, ETH_ALEN) != 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected GO Negotiation Request SA=" MACSTR
+               p2p_dbg(p2p, "Unexpected GO Negotiation Request SA=" MACSTR
                        " != dev_addr=" MACSTR,
                        MAC2STR(sa), MAC2STR(msg.p2p_device_addr));
                goto fail;
@@ -599,9 +559,8 @@ void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
        dev = p2p_get_device(p2p, sa);
 
        if (msg.status && *msg.status) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected Status attribute (%d) in GO "
-                       "Negotiation Request", *msg.status);
+               p2p_dbg(p2p, "Unexpected Status attribute (%d) in GO Negotiation Request",
+                       *msg.status);
                goto fail;
        }
 
@@ -610,120 +569,96 @@ void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
        else if (dev->flags & P2P_DEV_PROBE_REQ_ONLY)
                p2p_add_dev_info(p2p, sa, dev, &msg);
        if (dev && dev->flags & P2P_DEV_USER_REJECTED) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: User has rejected this peer");
+               p2p_dbg(p2p, "User has rejected this peer");
                status = P2P_SC_FAIL_REJECTED_BY_USER;
        } else if (dev == NULL || dev->wps_method == WPS_NOT_READY) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Not ready for GO negotiation with " MACSTR,
+               p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
                        MAC2STR(sa));
                status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
                p2p->cfg->go_neg_req_rx(p2p->cfg->cb_ctx, sa,
                                        msg.dev_password_id);
        } else if (p2p->go_neg_peer && p2p->go_neg_peer != dev) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Already in Group Formation with another peer");
+               p2p_dbg(p2p, "Already in Group Formation with another peer");
                status = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
        } else {
                int go;
 
                if (!p2p->go_neg_peer) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Starting "
-                               "GO Negotiation with previously authorized "
-                               "peer");
+                       p2p_dbg(p2p, "Starting GO Negotiation with previously authorized peer");
                        if (!(dev->flags & P2P_DEV_FORCE_FREQ)) {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: Use default channel settings");
+                               p2p_dbg(p2p, "Use default channel settings");
                                p2p->op_reg_class = p2p->cfg->op_reg_class;
                                p2p->op_channel = p2p->cfg->op_channel;
                                os_memcpy(&p2p->channels, &p2p->cfg->channels,
                                          sizeof(struct p2p_channels));
                        } else {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: Use previously configured "
-                                       "forced channel settings");
+                               p2p_dbg(p2p, "Use previously configured forced channel settings");
                        }
                }
 
                dev->flags &= ~P2P_DEV_NOT_YET_READY;
 
                if (!msg.go_intent) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: No GO Intent attribute received");
+                       p2p_dbg(p2p, "No GO Intent attribute received");
                        goto fail;
                }
                if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Invalid GO Intent value (%u) received",
+                       p2p_dbg(p2p, "Invalid GO Intent value (%u) received",
                                *msg.go_intent >> 1);
                        goto fail;
                }
 
                if (dev->go_neg_req_sent &&
                    os_memcmp(sa, p2p->cfg->dev_addr, ETH_ALEN) > 0) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Do not reply since peer has higher "
-                               "address and GO Neg Request already sent");
+                       p2p_dbg(p2p, "Do not reply since peer has higher address and GO Neg Request already sent");
                        p2p_parse_free(&msg);
                        return;
                }
 
                go = p2p_go_det(p2p->go_intent, *msg.go_intent);
                if (go < 0) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Incompatible GO Intent");
+                       p2p_dbg(p2p, "Incompatible GO Intent");
                        status = P2P_SC_FAIL_BOTH_GO_INTENT_15;
                        goto fail;
                }
 
                if (p2p_peer_channels(p2p, dev, msg.channel_list,
                                      msg.channel_list_len) < 0) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: No common channels found");
+                       p2p_dbg(p2p, "No common channels found");
                        status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
                        goto fail;
                }
 
                switch (msg.dev_password_id) {
                case DEV_PW_REGISTRAR_SPECIFIED:
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: PIN from peer Display");
+                       p2p_dbg(p2p, "PIN from peer Display");
                        if (dev->wps_method != WPS_PIN_KEYPAD) {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: We have wps_method=%s -> "
-                                       "incompatible",
+                               p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
                                        p2p_wps_method_str(dev->wps_method));
                                status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                                goto fail;
                        }
                        break;
                case DEV_PW_USER_SPECIFIED:
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Peer entered PIN on Keypad");
+                       p2p_dbg(p2p, "Peer entered PIN on Keypad");
                        if (dev->wps_method != WPS_PIN_DISPLAY) {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: We have wps_method=%s -> "
-                                       "incompatible",
+                               p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
                                        p2p_wps_method_str(dev->wps_method));
                                status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                                goto fail;
                        }
                        break;
                case DEV_PW_PUSHBUTTON:
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Peer using pushbutton");
+                       p2p_dbg(p2p, "Peer using pushbutton");
                        if (dev->wps_method != WPS_PBC) {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: We have wps_method=%s -> "
-                                       "incompatible",
+                               p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
                                        p2p_wps_method_str(dev->wps_method));
                                status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                                goto fail;
                        }
                        break;
                default:
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Unsupported Device Password ID %d",
+                       p2p_dbg(p2p, "Unsupported Device Password ID %d",
                                msg.dev_password_id);
                        status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                        goto fail;
@@ -735,16 +670,15 @@ void p2p_process_go_neg_req(struct p2p_data *p2p, const u8 *sa,
                dev->go_state = go ? LOCAL_GO : REMOTE_GO;
                dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
                                                     msg.operating_channel[4]);
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
-                       "channel preference: %d MHz", dev->oper_freq);
+               p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
+                       dev->oper_freq);
 
                if (msg.config_timeout) {
                        dev->go_timeout = msg.config_timeout[0];
                        dev->client_timeout = msg.config_timeout[1];
                }
 
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: GO Negotiation with " MACSTR, MAC2STR(sa));
+               p2p_dbg(p2p, "GO Negotiation with " MACSTR, MAC2STR(sa));
                if (p2p->state != P2P_IDLE)
                        p2p_stop_find_for_freq(p2p, rx_freq);
                p2p_set_state(p2p, P2P_GO_NEG);
@@ -763,16 +697,14 @@ fail:
        p2p_parse_free(&msg);
        if (resp == NULL)
                return;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending GO Negotiation Response");
+       p2p_dbg(p2p, "Sending GO Negotiation Response");
        if (rx_freq > 0)
                freq = rx_freq;
        else
                freq = p2p_channel_to_freq(p2p->cfg->reg_class,
                                           p2p->cfg->channel);
        if (freq < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unknown regulatory class/channel");
+               p2p_dbg(p2p, "Unknown regulatory class/channel");
                wpabuf_free(resp);
                return;
        }
@@ -796,8 +728,7 @@ fail:
        if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr,
                            p2p->cfg->dev_addr,
                            wpabuf_head(resp), wpabuf_len(resp), 500) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
 
        wpabuf_free(resp);
@@ -815,8 +746,7 @@ static struct wpabuf * p2p_build_go_neg_conf(struct p2p_data *p2p,
        u8 group_capab;
        size_t extra = 0;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Building GO Negotiation Confirm");
+       p2p_dbg(p2p, "Building GO Negotiation Confirm");
 
 #ifdef CONFIG_WIFI_DISPLAY
        if (p2p->wfd_ie_go_neg)
@@ -881,14 +811,12 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
        u8 status = P2P_SC_SUCCESS;
        int freq;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received GO Negotiation Response from " MACSTR
+       p2p_dbg(p2p, "Received GO Negotiation Response from " MACSTR
                " (freq=%d)", MAC2STR(sa), rx_freq);
        dev = p2p_get_device(p2p, sa);
        if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
            dev != p2p->go_neg_peer) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Not ready for GO negotiation with " MACSTR,
+               p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
                        MAC2STR(sa));
                return;
        }
@@ -897,44 +825,35 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
                return;
 
        if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_RESPONSE)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Was not expecting GO Negotiation Response - "
-                       "ignore");
+               p2p_dbg(p2p, "Was not expecting GO Negotiation Response - ignore");
                p2p_parse_free(&msg);
                return;
        }
        dev->flags &= ~P2P_DEV_WAIT_GO_NEG_RESPONSE;
 
        if (msg.dialog_token != dev->dialog_token) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected Dialog Token %u (expected %u)",
+               p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
                        msg.dialog_token, dev->dialog_token);
                p2p_parse_free(&msg);
                return;
        }
 
        if (!msg.status) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Status attribute received");
+               p2p_dbg(p2p, "No Status attribute received");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
        if (*msg.status) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: GO Negotiation rejected: status %d",
-                       *msg.status);
+               p2p_dbg(p2p, "GO Negotiation rejected: status %d", *msg.status);
                dev->go_neg_req_sent = 0;
                if (*msg.status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Wait for the peer to become ready for "
-                               "GO Negotiation");
+                       p2p_dbg(p2p, "Wait for the peer to become ready for GO Negotiation");
                        dev->flags |= P2P_DEV_NOT_YET_READY;
                        dev->wait_count = 0;
                        p2p_set_state(p2p, P2P_WAIT_PEER_IDLE);
                        p2p_set_timeout(p2p, 0, 0);
                } else {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Stop GO Negotiation attempt");
+                       p2p_dbg(p2p, "Stop GO Negotiation attempt");
                        p2p_go_neg_failed(p2p, dev, *msg.status);
                }
                p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
@@ -943,9 +862,7 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
        }
 
        if (!msg.capability) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Capability attribute missing from GO "
-                       "Negotiation Response");
+               p2p_dbg(p2p, "Mandatory Capability attribute missing from GO Negotiation Response");
 #ifdef CONFIG_P2P_STRICT
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
@@ -953,9 +870,7 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
        }
 
        if (!msg.p2p_device_info) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory P2P Device Info attribute missing "
-                       "from GO Negotiation Response");
+               p2p_dbg(p2p, "Mandatory P2P Device Info attribute missing from GO Negotiation Response");
 #ifdef CONFIG_P2P_STRICT
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
@@ -963,22 +878,18 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
        }
 
        if (!msg.intended_addr) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Intended P2P Interface Address attribute "
-                       "received");
+               p2p_dbg(p2p, "No Intended P2P Interface Address attribute received");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
 
        if (!msg.go_intent) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No GO Intent attribute received");
+               p2p_dbg(p2p, "No GO Intent attribute received");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
        if ((*msg.go_intent >> 1) > P2P_MAX_GO_INTENT) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid GO Intent value (%u) received",
+               p2p_dbg(p2p, "Invalid GO Intent value (%u) received",
                        *msg.go_intent >> 1);
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
@@ -986,8 +897,7 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
 
        go = p2p_go_det(p2p->go_intent, *msg.go_intent);
        if (go < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Incompatible GO Intent");
+               p2p_dbg(p2p, "Incompatible GO Intent");
                status = P2P_SC_FAIL_INCOMPATIBLE_PARAMS;
                goto fail;
        }
@@ -997,18 +907,14 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
                p2p->ssid_len = msg.group_id_len - ETH_ALEN;
                os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
        } else if (!go) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory P2P Group ID attribute missing from "
-                       "GO Negotiation Response");
+               p2p_dbg(p2p, "Mandatory P2P Group ID attribute missing from GO Negotiation Response");
                p2p->ssid_len = 0;
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
 
        if (!msg.config_timeout) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Configuration Timeout attribute "
-                       "missing from GO Negotiation Response");
+               p2p_dbg(p2p, "Mandatory Configuration Timeout attribute missing from GO Negotiation Response");
 #ifdef CONFIG_P2P_STRICT
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
@@ -1023,22 +929,19 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
                 * Note: P2P Client may omit Operating Channel attribute to
                 * indicate it does not have a preference.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Operating Channel attribute received");
+               p2p_dbg(p2p, "No Operating Channel attribute received");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
        if (!msg.channel_list) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Channel List attribute received");
+               p2p_dbg(p2p, "No Channel List attribute received");
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
 
        if (p2p_peer_channels(p2p, dev, msg.channel_list,
                              msg.channel_list_len) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No common channels found");
+               p2p_dbg(p2p, "No common channels found");
                status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
                goto fail;
        }
@@ -1046,51 +949,41 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
        if (msg.operating_channel) {
                dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
                                                     msg.operating_channel[4]);
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
-                       "channel preference: %d MHz", dev->oper_freq);
+               p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
+                       dev->oper_freq);
        } else
                dev->oper_freq = 0;
 
        switch (msg.dev_password_id) {
        case DEV_PW_REGISTRAR_SPECIFIED:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: PIN from peer Display");
+               p2p_dbg(p2p, "PIN from peer Display");
                if (dev->wps_method != WPS_PIN_KEYPAD) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: We have wps_method=%s -> "
-                               "incompatible",
+                       p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
                                p2p_wps_method_str(dev->wps_method));
                        status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                        goto fail;
                }
                break;
        case DEV_PW_USER_SPECIFIED:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Peer entered PIN on Keypad");
+               p2p_dbg(p2p, "Peer entered PIN on Keypad");
                if (dev->wps_method != WPS_PIN_DISPLAY) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: We have wps_method=%s -> "
-                               "incompatible",
+                       p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
                                p2p_wps_method_str(dev->wps_method));
                        status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                        goto fail;
                }
                break;
        case DEV_PW_PUSHBUTTON:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Peer using pushbutton");
+               p2p_dbg(p2p, "Peer using pushbutton");
                if (dev->wps_method != WPS_PBC) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: We have wps_method=%s -> "
-                               "incompatible",
+                       p2p_dbg(p2p, "We have wps_method=%s -> incompatible",
                                p2p_wps_method_str(dev->wps_method));
                        status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                        goto fail;
                }
                break;
        default:
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported Device Password ID %d",
+               p2p_dbg(p2p, "Unsupported Device Password ID %d",
                        msg.dev_password_id);
                status = P2P_SC_FAIL_INCOMPATIBLE_PROV_METHOD;
                goto fail;
@@ -1102,8 +995,7 @@ void p2p_process_go_neg_resp(struct p2p_data *p2p, const u8 *sa,
        p2p_set_state(p2p, P2P_GO_NEG);
        p2p_clear_timeout(p2p);
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GO Negotiation with " MACSTR, MAC2STR(sa));
+       p2p_dbg(p2p, "GO Negotiation with " MACSTR, MAC2STR(sa));
        os_memcpy(dev->intended_addr, msg.intended_addr, ETH_ALEN);
 
 fail:
@@ -1112,8 +1004,7 @@ fail:
        p2p_parse_free(&msg);
        if (conf == NULL)
                return;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending GO Negotiation Confirm");
+       p2p_dbg(p2p, "Sending GO Negotiation Confirm");
        if (status == P2P_SC_SUCCESS) {
                p2p->pending_action_state = P2P_PENDING_GO_NEG_CONFIRM;
                dev->go_state = go ? LOCAL_GO : REMOTE_GO;
@@ -1125,14 +1016,12 @@ fail:
                freq = dev->listen_freq;
        if (p2p_send_action(p2p, freq, sa, p2p->cfg->dev_addr, sa,
                            wpabuf_head(conf), wpabuf_len(conf), 0) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
                p2p_go_neg_failed(p2p, dev, -1);
        }
        wpabuf_free(conf);
        if (status != P2P_SC_SUCCESS) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: GO Negotiation failed");
+               p2p_dbg(p2p, "GO Negotiation failed");
                p2p_go_neg_failed(p2p, dev, status);
        }
 }
@@ -1144,22 +1033,18 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
        struct p2p_device *dev;
        struct p2p_message msg;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received GO Negotiation Confirm from " MACSTR,
+       p2p_dbg(p2p, "Received GO Negotiation Confirm from " MACSTR,
                MAC2STR(sa));
        dev = p2p_get_device(p2p, sa);
        if (dev == NULL || dev->wps_method == WPS_NOT_READY ||
            dev != p2p->go_neg_peer) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Not ready for GO negotiation with " MACSTR,
+               p2p_dbg(p2p, "Not ready for GO negotiation with " MACSTR,
                        MAC2STR(sa));
                return;
        }
 
        if (p2p->pending_action_state == P2P_PENDING_GO_NEG_RESPONSE) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Stopped waiting "
-                       "for TX status on GO Negotiation Response since we "
-                       "already received Confirmation");
+               p2p_dbg(p2p, "Stopped waiting for TX status on GO Negotiation Response since we already received Confirmation");
                p2p->pending_action_state = P2P_NO_PENDING_ACTION;
        }
 
@@ -1167,31 +1052,25 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
                return;
 
        if (!(dev->flags & P2P_DEV_WAIT_GO_NEG_CONFIRM)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Was not expecting GO Negotiation Confirm - "
-                       "ignore");
+               p2p_dbg(p2p, "Was not expecting GO Negotiation Confirm - ignore");
                return;
        }
        dev->flags &= ~P2P_DEV_WAIT_GO_NEG_CONFIRM;
 
        if (msg.dialog_token != dev->dialog_token) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected Dialog Token %u (expected %u)",
+               p2p_dbg(p2p, "Unexpected Dialog Token %u (expected %u)",
                        msg.dialog_token, dev->dialog_token);
                p2p_parse_free(&msg);
                return;
        }
 
        if (!msg.status) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Status attribute received");
+               p2p_dbg(p2p, "No Status attribute received");
                p2p_parse_free(&msg);
                return;
        }
        if (*msg.status) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: GO Negotiation rejected: status %d",
-                       *msg.status);
+               p2p_dbg(p2p, "GO Negotiation rejected: status %d", *msg.status);
                p2p_go_neg_failed(p2p, dev, *msg.status);
                p2p_parse_free(&msg);
                return;
@@ -1202,9 +1081,7 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
                p2p->ssid_len = msg.group_id_len - ETH_ALEN;
                os_memcpy(p2p->ssid, msg.group_id + ETH_ALEN, p2p->ssid_len);
        } else if (dev->go_state == REMOTE_GO) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory P2P Group ID attribute missing from "
-                       "GO Negotiation Confirmation");
+               p2p_dbg(p2p, "Mandatory P2P Group ID attribute missing from GO Negotiation Confirmation");
                p2p->ssid_len = 0;
                p2p_go_neg_failed(p2p, dev, P2P_SC_FAIL_INVALID_PARAMS);
                p2p_parse_free(&msg);
@@ -1212,9 +1089,7 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
        }
 
        if (!msg.operating_channel) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Operating Channel attribute missing "
-                       "from GO Negotiation Confirmation");
+               p2p_dbg(p2p, "Mandatory Operating Channel attribute missing from GO Negotiation Confirmation");
 #ifdef CONFIG_P2P_STRICT
                p2p_parse_free(&msg);
                return;
@@ -1225,16 +1100,14 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
        if (msg.operating_channel) {
                dev->oper_freq = p2p_channel_to_freq(msg.operating_channel[3],
                                                     msg.operating_channel[4]);
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer operating "
-                       "channel preference: %d MHz", dev->oper_freq);
+               p2p_dbg(p2p, "P2P: Peer operating channel preference: %d MHz",
+                       dev->oper_freq);
        } else
                dev->oper_freq = 0;
 #endif
 
        if (!msg.channel_list) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Operating Channel attribute missing "
-                       "from GO Negotiation Confirmation");
+               p2p_dbg(p2p, "Mandatory Operating Channel attribute missing from GO Negotiation Confirmation");
 #ifdef CONFIG_P2P_STRICT
                p2p_parse_free(&msg);
                return;
@@ -1248,9 +1121,7 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
                 * This should not happen since GO negotiation has already
                 * been completed.
                 */
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected GO Neg state - do not know which end "
-                       "becomes GO");
+               p2p_dbg(p2p, "Unexpected GO Neg state - do not know which end becomes GO");
                return;
        }
 
@@ -1262,8 +1133,7 @@ void p2p_process_go_neg_conf(struct p2p_data *p2p, const u8 *sa,
         * the group so that we will remain on the current channel to
         * acknowledge any possible retransmission from the peer.
         */
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: 20 ms wait on current "
-               "channel before starting group");
+       p2p_dbg(p2p, "20 ms wait on current channel before starting group");
        os_sleep(0, 20000);
 
        p2p_go_complete(p2p, dev);
index 852ddf5..15e7622 100644 (file)
@@ -378,8 +378,8 @@ wifi_display_build_go_ie(struct p2p_group *group)
        } else {
                WPA_PUT_BE16(len, (u8 *) wpabuf_put(wfd_subelems, 0) - len -
                             2);
-               wpa_printf(MSG_DEBUG, "WFD: WFD Session Info: %u descriptors",
-                          count);
+               p2p_dbg(group->p2p, "WFD: WFD Session Info: %u descriptors",
+                       count);
        }
 
        wfd_ie = wifi_display_encaps(wfd_subelems);
@@ -588,7 +588,7 @@ int p2p_group_notif_assoc(struct p2p_group *group, const u8 *addr,
        m->next = group->members;
        group->members = m;
        group->num_members++;
-       wpa_msg(group->p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Add client " MACSTR
+       p2p_dbg(group->p2p,  "Add client " MACSTR
                " to group (p2p=%d wfd=%d client_info=%d); num_members=%u/%u",
                MAC2STR(addr), m->p2p_ie ? 1 : 0, m->wfd_ie ? 1 : 0,
                m->client_info ? 1 : 0,
@@ -641,8 +641,8 @@ struct wpabuf * p2p_group_assoc_resp_ie(struct p2p_group *group, u8 status)
 void p2p_group_notif_disassoc(struct p2p_group *group, const u8 *addr)
 {
        if (p2p_group_remove_member(group, addr)) {
-               wpa_msg(group->p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Remove "
-                       "client " MACSTR " from group; num_members=%u/%u",
+               p2p_dbg(group->p2p, "Remove client " MACSTR
+                       " from group; num_members=%u/%u",
                        MAC2STR(addr), group->num_members,
                        group->cfg->max_clients);
                if (group->num_members == group->cfg->max_clients - 1)
@@ -854,20 +854,18 @@ int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id,
 
        m = p2p_group_get_client(group, dev_id);
        if (m == NULL || m->client_info == NULL) {
-               wpa_printf(MSG_DEBUG, "P2P: Requested client was not in this "
-                          "group " MACSTR,
-                          MAC2STR(group->cfg->interface_addr));
+               p2p_dbg(group->p2p, "Requested client was not in this group "
+                       MACSTR, MAC2STR(group->cfg->interface_addr));
                return -1;
        }
 
        if (!(m->dev_capab & P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
-               wpa_printf(MSG_DEBUG, "P2P: Requested client does not support "
-                          "client discoverability");
+               p2p_dbg(group->p2p, "Requested client does not support client discoverability");
                return -1;
        }
 
-       wpa_printf(MSG_DEBUG, "P2P: Schedule GO Discoverability Request to be "
-                  "sent to " MACSTR, MAC2STR(dev_id));
+       p2p_dbg(group->p2p, "Schedule GO Discoverability Request to be sent to "
+               MACSTR, MAC2STR(dev_id));
 
        req = p2p_build_go_disc_req();
        if (req == NULL)
@@ -882,8 +880,7 @@ int p2p_group_go_discover(struct p2p_group *group, const u8 *dev_id,
                                  group->cfg->interface_addr,
                                  wpabuf_head(req), wpabuf_len(req), 200) < 0)
        {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
 
        wpabuf_free(req);
@@ -908,7 +905,7 @@ u8 p2p_group_presence_req(struct p2p_group *group,
 
        m = p2p_group_get_client_iface(group, client_interface_addr);
        if (m == NULL || m->client_info == NULL) {
-               wpa_printf(MSG_DEBUG, "P2P: Client was not in this group");
+               p2p_dbg(group->p2p, "Client was not in this group");
                return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
        }
 
@@ -921,9 +918,9 @@ u8 p2p_group_presence_req(struct p2p_group *group,
        else
                curr_noa_len = -1;
        if (curr_noa_len < 0)
-               wpa_printf(MSG_DEBUG, "P2P: Failed to fetch current NoA");
+               p2p_dbg(group->p2p, "Failed to fetch current NoA");
        else if (curr_noa_len == 0)
-               wpa_printf(MSG_DEBUG, "P2P: No NoA being advertized");
+               p2p_dbg(group->p2p, "No NoA being advertized");
        else
                wpa_hexdump(MSG_DEBUG, "P2P: Current NoA", curr_noa,
                            curr_noa_len);
index 81a0b27..dc629f8 100644 (file)
@@ -730,5 +730,11 @@ int p2p_send_action(struct p2p_data *p2p, unsigned int freq, const u8 *dst,
 void p2p_stop_listen_for_freq(struct p2p_data *p2p, int freq);
 int p2p_prepare_channel(struct p2p_data *p2p, struct p2p_device *dev,
                        unsigned int force_freq, unsigned int pref_freq);
+void p2p_dbg(struct p2p_data *p2p, const char *fmt, ...)
+PRINTF_FORMAT(2, 3);
+void p2p_info(struct p2p_data *p2p, const char *fmt, ...)
+PRINTF_FORMAT(2, 3);
+void p2p_err(struct p2p_data *p2p, const char *fmt, ...)
+PRINTF_FORMAT(2, 3);
 
 #endif /* P2P_I_H */
index 5016f1b..214eae0 100644 (file)
@@ -166,8 +166,7 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
 
        os_memset(group_bssid, 0, sizeof(group_bssid));
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received Invitation Request from " MACSTR " (freq=%d)",
+       p2p_dbg(p2p, "Received Invitation Request from " MACSTR " (freq=%d)",
                MAC2STR(sa), rx_freq);
 
        if (p2p_parse(data, len, &msg))
@@ -175,14 +174,12 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
 
        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));
+               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)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Invitation Request add device failed "
+                       p2p_dbg(p2p, "Invitation Request add device failed "
                                MACSTR, MAC2STR(sa));
                        status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
                        goto fail;
@@ -190,18 +187,16 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
 
                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));
+                       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) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory attribute missing in Invitation "
-                       "Request from " MACSTR, MAC2STR(sa));
+               p2p_dbg(p2p, "Mandatory attribute missing in Invitation Request from "
+                       MACSTR, MAC2STR(sa));
                status = P2P_SC_FAIL_INVALID_PARAMS;
                goto fail;
        }
@@ -214,16 +209,14 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
                 * 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");
+               p2p_dbg(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");
+               p2p_dbg(p2p, "No common channels found");
                status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
                goto fail;
        }
@@ -236,12 +229,11 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
        }
 
        if (op_freq) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Invitation "
-                       "processing forced frequency %d MHz", op_freq);
+               p2p_dbg(p2p, "Invitation processing forced frequency %d MHz",
+                       op_freq);
                if (p2p_freq_to_channel(op_freq, &reg_class, &channel) < 0) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Unknown forced freq %d MHz from "
-                               "invitation_process()", op_freq);
+                       p2p_dbg(p2p, "Unknown forced freq %d MHz from invitation_process()",
+                               op_freq);
                        status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
                        goto fail;
                }
@@ -250,9 +242,8 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
                                       &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);
+                       p2p_dbg(p2p, "forced freq %d MHz not in the supported channels interaction",
+                               op_freq);
                        status = P2P_SC_FAIL_NO_COMMON_CHANNELS;
                        goto fail;
                }
@@ -260,17 +251,14 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
                if (status == P2P_SC_SUCCESS)
                        channels = &intersection;
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No forced channel from invitation processing - "
-                       "figure out best one to use");
+               p2p_dbg(p2p, "No forced channel from invitation processing - figure out best one to use");
 
                p2p_channels_intersect(&p2p->cfg->channels, &dev->channels,
                                       &intersection);
                /* Default to own configuration as a starting point */
                p2p->op_reg_class = p2p->cfg->op_reg_class;
                p2p->op_channel = p2p->cfg->op_channel;
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Own default "
-                       "op_class %d channel %d",
+               p2p_dbg(p2p, "Own default op_class %d channel %d",
                        p2p->op_reg_class, p2p->op_channel);
 
                /* Use peer preference if specified and compatible */
@@ -279,8 +267,7 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
                        req_freq = p2p_channel_to_freq(
                                msg.operating_channel[3],
                                msg.operating_channel[4]);
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer "
-                               "operating channel preference: %d MHz",
+                       p2p_dbg(p2p, "Peer operating channel preference: %d MHz",
                                req_freq);
                        if (req_freq > 0 &&
                            p2p_channels_includes(&intersection,
@@ -288,46 +275,31 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
                                                  msg.operating_channel[4])) {
                                p2p->op_reg_class = msg.operating_channel[3];
                                p2p->op_channel = msg.operating_channel[4];
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: Use peer preference op_class %d "
-                                       "channel %d",
+                               p2p_dbg(p2p, "Use peer preference op_class %d channel %d",
                                        p2p->op_reg_class, p2p->op_channel);
                        } else {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: Cannot use peer channel "
-                                       "preference");
+                               p2p_dbg(p2p, "Cannot use peer channel preference");
                        }
                }
 
                if (!p2p_channels_includes(&intersection, p2p->op_reg_class,
                                           p2p->op_channel)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Initially selected channel (op_class %d "
-                               "channel %d) not in channel intersection - try "
-                               "to reselect",
+                       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);
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Re-selection result: op_class %d "
-                               "channel %d",
+                       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)) {
-                               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                                       "P2P: Peer does not support selected "
-                                       "operating channel (reg_class=%u "
-                                       "channel=%u)",
+                               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 (!(dev->flags & P2P_DEV_FORCE_FREQ) &&
                           !p2p->cfg->cfg_op_channel) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Try to reselect channel selection with "
-                               "peer information received; "
-                               "previously selected op_class %u channel %u",
+                       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);
                }
@@ -335,16 +307,13 @@ void p2p_process_invitation_req(struct p2p_data *p2p, const u8 *sa,
                op_freq = p2p_channel_to_freq(p2p->op_reg_class,
                                              p2p->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_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;
                }
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Selected operating "
-                       "channel - %d MHz", op_freq);
+               p2p_dbg(p2p, "Selected operating channel - %d MHz", op_freq);
 
                if (status == P2P_SC_SUCCESS) {
                        reg_class = p2p->op_reg_class;
@@ -370,8 +339,7 @@ fail:
                freq = p2p_channel_to_freq(p2p->cfg->reg_class,
                                           p2p->cfg->channel);
        if (freq < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unknown regulatory class/channel");
+               p2p_dbg(p2p, "Unknown regulatory class/channel");
                goto out;
        }
 
@@ -398,8 +366,7 @@ fail:
        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");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
 
 out:
@@ -415,21 +382,18 @@ void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa,
        struct p2p_message msg;
        struct p2p_channels intersection, *channels = NULL;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received Invitation Response from " MACSTR,
+       p2p_dbg(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 "
+               p2p_dbg(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 "
+               p2p_dbg(p2p, "Ignore unexpected Invitation Response from peer "
                        MACSTR, MAC2STR(sa));
                return;
        }
@@ -438,17 +402,15 @@ void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa,
                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_dbg(p2p, "Mandatory Status attribute missing in Invitation Response from "
+                       MACSTR, MAC2STR(sa));
                p2p_parse_free(&msg);
                return;
        }
 
        if (!msg.channel_list) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Mandatory Channel List attribute missing in "
-                       "Invitation Response from " MACSTR, MAC2STR(sa));
+               p2p_dbg(p2p, "Mandatory Channel List attribute missing in Invitation Response from "
+                       MACSTR, MAC2STR(sa));
 #ifdef CONFIG_P2P_STRICT
                p2p_parse_free(&msg);
                return;
@@ -458,8 +420,7 @@ void p2p_process_invitation_resp(struct p2p_data *p2p, const u8 *sa,
        } else if (p2p_peer_channels_check(p2p, &p2p->channels, dev,
                                           msg.channel_list,
                                           msg.channel_list_len) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No common channels found");
+               p2p_dbg(p2p, "No common channels found");
                p2p_parse_free(&msg);
                return;
        } else {
@@ -488,9 +449,8 @@ int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
 
        freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
        if (freq <= 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Listen/Operating frequency known for the "
-                       "peer " MACSTR " to send Invitation Request",
+               p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
+                       MACSTR " to send Invitation Request",
                        MAC2STR(dev->info.p2p_device_addr));
                return -1;
        }
@@ -500,8 +460,7 @@ int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
                return -1;
        if (p2p->state != P2P_IDLE)
                p2p_stop_listen_for_freq(p2p, freq);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending Invitation Request");
+       p2p_dbg(p2p, "Sending Invitation Request");
        p2p_set_state(p2p, P2P_INVITE);
        p2p->pending_action_state = P2P_PENDING_INVITATION_REQUEST;
        p2p->invite_peer = dev;
@@ -509,8 +468,7 @@ int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
        if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
                            p2p->cfg->dev_addr, dev->info.p2p_device_addr,
                            wpabuf_head(req), wpabuf_len(req), 200) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
                /* Use P2P find to recover and retry */
                p2p_set_timeout(p2p, 0, 0);
        }
@@ -523,12 +481,10 @@ int p2p_invite_send(struct p2p_data *p2p, struct p2p_device *dev,
 
 void p2p_invitation_req_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Invitation Request TX callback: success=%d", success);
+       p2p_dbg(p2p, "Invitation Request TX callback: success=%d", success);
 
        if (p2p->invite_peer == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No pending Invite");
+               p2p_dbg(p2p, "No pending Invite");
                return;
        }
 
@@ -547,15 +503,11 @@ void p2p_invitation_req_cb(struct p2p_data *p2p, int success)
 
 void p2p_invitation_resp_cb(struct p2p_data *p2p, int success)
 {
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Invitation Response TX callback: success=%d", success);
+       p2p_dbg(p2p, "Invitation Response TX callback: success=%d", success);
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
 
        if (!success)
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Assume Invitation Response was actually "
-                       "received by the peer even though Ack was not "
-                       "reported");
+               p2p_dbg(p2p, "Assume Invitation Response was actually received by the peer even though Ack was not reported");
 
        if (p2p->cfg->invitation_received) {
                p2p->cfg->invitation_received(p2p->cfg->cb_ctx,
@@ -576,28 +528,24 @@ int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
 {
        struct p2p_device *dev;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Request to invite peer " MACSTR " role=%d persistent=%d "
+       p2p_dbg(p2p, "Request to invite peer " MACSTR " role=%d persistent=%d "
                "force_freq=%u",
                MAC2STR(peer), role, persistent_group, force_freq);
        if (bssid)
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invitation for BSSID " MACSTR, MAC2STR(bssid));
+               p2p_dbg(p2p, "Invitation for BSSID " MACSTR, MAC2STR(bssid));
        if (go_dev_addr) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invitation for GO Device Address " MACSTR,
+               p2p_dbg(p2p, "Invitation for GO Device Address " MACSTR,
                        MAC2STR(go_dev_addr));
                os_memcpy(p2p->invite_go_dev_addr_buf, go_dev_addr, ETH_ALEN);
                p2p->invite_go_dev_addr = p2p->invite_go_dev_addr_buf;
        } else
                p2p->invite_go_dev_addr = NULL;
-       wpa_hexdump_ascii(MSG_DEBUG, "P2P: Invitation for SSID",
+       wpa_hexdump_ascii(MSG_DEBUG, "Invitation for SSID",
                          ssid, ssid_len);
 
        dev = p2p_get_device(p2p, peer);
        if (dev == NULL || (dev->listen_freq <= 0 && dev->oper_freq <= 0)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Cannot invite unknown P2P Device " MACSTR,
+               p2p_dbg(p2p, "Cannot invite unknown P2P Device " MACSTR,
                        MAC2STR(peer));
                return -1;
        }
@@ -614,8 +562,7 @@ int p2p_invite(struct p2p_data *p2p, const u8 *peer, enum p2p_invite_role role,
        if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
                if (!(dev->info.dev_capab &
                      P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Cannot invite a P2P Device " MACSTR
+                       p2p_dbg(p2p, "Cannot invite a P2P Device " MACSTR
                                " that is in a group and is not discoverable",
                                MAC2STR(peer));
                }
index 3bbce16..54aa428 100644 (file)
@@ -141,22 +141,19 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
        if (p2p_parse(data, len, &msg))
                return;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received Provision Discovery Request from " MACSTR
+       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)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Provision Discovery Request from "
-                       "unknown peer " MACSTR, MAC2STR(sa));
+               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)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Provision Discovery Request add device "
-                               "failed " MACSTR, MAC2STR(sa));
+                       p2p_dbg(p2p, "Provision Discovery Request add device failed "
+                               MACSTR, MAC2STR(sa));
                }
        } else if (msg.wfd_subelems) {
                wpabuf_free(dev->info.wfd_subelems);
@@ -166,8 +163,7 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *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");
+               p2p_dbg(p2p, "Unsupported Config Methods in Provision Discovery Request");
                goto out;
        }
 
@@ -180,8 +176,7 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
                                break;
                }
                if (i == p2p->num_groups) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: PD "
-                               "request for unknown P2P Group ID - reject");
+                       p2p_dbg(p2p, "PD request for unknown P2P Group ID - reject");
                        goto out;
                }
        }
@@ -190,12 +185,12 @@ void p2p_process_prov_disc_req(struct p2p_data *p2p, const u8 *sa,
                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
+               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) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
+               p2p_dbg(p2p, "Peer " MACSTR
                        " requested us to write its PIN using keypad",
                        MAC2STR(sa));
                if (dev)
@@ -212,16 +207,14 @@ out:
                p2p_parse_free(&msg);
                return;
        }
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Sending Provision Discovery Response");
+       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) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unknown regulatory class/channel");
+               p2p_dbg(p2p, "Unknown regulatory class/channel");
                wpabuf_free(resp);
                p2p_parse_free(&msg);
                return;
@@ -230,8 +223,7 @@ out:
        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");
+               p2p_dbg(p2p, "Failed to send Action frame");
        }
 
        wpabuf_free(resp);
@@ -264,24 +256,20 @@ void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
        if (p2p_parse(data, len, &msg))
                return;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received Provision Discovery Response from " MACSTR
+       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) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore Provision Discovery Response from "
-                       MACSTR " with no pending request", MAC2STR(sa));
+               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) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore Provision Discovery Response with "
-                       "unexpected Dialog Token %u (expected %u)",
+               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;
@@ -307,9 +295,7 @@ void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
                p2p_reset_pending_pd(p2p);
 
        if (msg.wps_config_methods != req_config_methods) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer rejected "
-                       "our Provision Discovery Request (received "
-                       "config_methods 0x%x expected 0x%x",
+               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,
@@ -322,11 +308,11 @@ void p2p_process_prov_disc_resp(struct p2p_data *p2p, const u8 *sa,
        dev->flags &= ~(P2P_DEV_PD_PEER_DISPLAY |
                        P2P_DEV_PD_PEER_KEYPAD);
        if (req_config_methods & WPS_CONFIG_DISPLAY) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
+               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) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Peer " MACSTR
+               p2p_dbg(p2p, "Peer " MACSTR
                        " accepted to write our PIN using keypad",
                        MAC2STR(sa));
                dev->flags |= P2P_DEV_PD_PEER_KEYPAD;
@@ -342,10 +328,8 @@ out:
        dev->req_config_methods = 0;
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
        if (dev->flags & P2P_DEV_PD_BEFORE_GO_NEG) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Start GO Neg after the PD-before-GO-Neg "
-                       "workaround with " MACSTR,
-                       MAC2STR(dev->info.p2p_device_addr));
+               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;
@@ -373,9 +357,8 @@ int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
                freq = dev->listen_freq > 0 ? dev->listen_freq :
                        dev->oper_freq;
        if (freq <= 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Listen/Operating frequency known for the "
-                       "peer " MACSTR " to send Provision Discovery Request",
+               p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
+                       MACSTR " to send Provision Discovery Request",
                        MAC2STR(dev->info.p2p_device_addr));
                return -1;
        }
@@ -383,8 +366,7 @@ int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
        if (dev->flags & P2P_DEV_GROUP_CLIENT_ONLY) {
                if (!(dev->info.dev_capab &
                      P2P_DEV_CAPAB_CLIENT_DISCOVERABILITY)) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Cannot use PD with P2P Device " MACSTR
+                       p2p_dbg(p2p, "Cannot use PD with P2P Device " MACSTR
                                " that is in a group and is not discoverable",
                                MAC2STR(dev->info.p2p_device_addr));
                        return -1;
@@ -404,8 +386,7 @@ int p2p_send_prov_disc_req(struct p2p_data *p2p, struct p2p_device *dev,
        if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
                            p2p->cfg->dev_addr, dev->info.p2p_device_addr,
                            wpabuf_head(req), wpabuf_len(req), 200) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
                wpabuf_free(req);
                return -1;
        }
@@ -427,14 +408,13 @@ int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
        if (dev == NULL)
                dev = p2p_get_device_interface(p2p, peer_addr);
        if (dev == NULL || (dev->flags & P2P_DEV_PROBE_REQ_ONLY)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Provision "
-                       "Discovery Request destination " MACSTR
+               p2p_dbg(p2p, "Provision Discovery Request destination " MACSTR
                        " not yet known", MAC2STR(peer_addr));
                return -1;
        }
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Provision Discovery "
-               "Request with " MACSTR " (config methods 0x%x)",
+       p2p_dbg(p2p, "Provision Discovery Request with " MACSTR
+               " (config methods 0x%x)",
                MAC2STR(peer_addr), config_methods);
        if (config_methods == 0)
                return -1;
@@ -450,9 +430,8 @@ int p2p_prov_disc_req(struct p2p_data *p2p, const u8 *peer_addr,
 
        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)",
+               p2p_dbg(p2p, "Busy with other operations; postpone Provision Discovery Request with "
+                       MACSTR " (config methods 0x%x)",
                        MAC2STR(peer_addr), config_methods);
                return 0;
        }
index d8daa59..5d9c1bb 100644 (file)
@@ -157,8 +157,7 @@ static void p2p_send_gas_comeback_req(struct p2p_data *p2p, const u8 *dst,
        p2p->pending_action_state = P2P_NO_PENDING_ACTION;
        if (p2p_send_action(p2p, freq, dst, p2p->cfg->dev_addr, dst,
                            wpabuf_head(req), wpabuf_len(req), 200) < 0)
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
 
        wpabuf_free(req);
 }
@@ -235,9 +234,8 @@ int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev)
 
        freq = dev->listen_freq > 0 ? dev->listen_freq : dev->oper_freq;
        if (freq <= 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: No Listen/Operating frequency known for the "
-                       "peer " MACSTR " to send SD Request",
+               p2p_dbg(p2p, "No Listen/Operating frequency known for the peer "
+                       MACSTR " to send SD Request",
                        MAC2STR(dev->info.p2p_device_addr));
                return -1;
        }
@@ -246,8 +244,7 @@ int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev)
        if (query == NULL)
                return -1;
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Start Service Discovery with " MACSTR,
+       p2p_dbg(p2p, "Start Service Discovery with " MACSTR,
                MAC2STR(dev->info.p2p_device_addr));
 
        req = p2p_build_sd_query(p2p->srv_update_indic, query->tlvs);
@@ -261,8 +258,7 @@ int p2p_start_sd(struct p2p_data *p2p, struct p2p_device *dev)
        if (p2p_send_action(p2p, freq, dev->info.p2p_device_addr,
                            p2p->cfg->dev_addr, dev->info.p2p_device_addr,
                            wpabuf_head(req), wpabuf_len(req), 5000) < 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Failed to send Action frame");
+               p2p_dbg(p2p, "Failed to send Action frame");
                ret = -1;
        }
 
@@ -299,14 +295,12 @@ void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
                return;
 
        dialog_token = *pos++;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: GAS Initial Request from " MACSTR " (dialog token %u, "
-               "freq %d)",
+       p2p_dbg(p2p, "GAS Initial Request from " MACSTR
+               " (dialog token %u, freq %d)",
                MAC2STR(sa), dialog_token, rx_freq);
 
        if (*pos != WLAN_EID_ADV_PROTO) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected IE in GAS Initial Request: %u", *pos);
+               p2p_dbg(p2p, "Unexpected IE in GAS Initial Request: %u", *pos);
                return;
        }
        pos++;
@@ -314,15 +308,13 @@ void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
        slen = *pos++;
        next = pos + slen;
        if (next > end || slen < 2) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid IE in GAS Initial Request");
+               p2p_dbg(p2p, "Invalid IE in GAS Initial Request");
                return;
        }
        pos++; /* skip QueryRespLenLimit and PAME-BI */
 
        if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported GAS advertisement protocol id %u",
+               p2p_dbg(p2p, "Unsupported GAS advertisement protocol id %u",
                        *pos);
                return;
        }
@@ -341,8 +333,7 @@ void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
        if (pos + 4 > end)
                return;
        if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
+               p2p_dbg(p2p, "Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
                return;
        }
        pos += 2;
@@ -350,21 +341,18 @@ void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
        slen = WPA_GET_LE16(pos);
        pos += 2;
        if (pos + slen > end || slen < 3 + 1) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid ANQP Query Request length");
+               p2p_dbg(p2p, "Invalid ANQP Query Request length");
                return;
        }
 
        if (WPA_GET_BE24(pos) != OUI_WFA) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
+               p2p_dbg(p2p, "Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
                return;
        }
        pos += 3;
 
        if (*pos != P2P_OUI_TYPE) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP vendor type %u", *pos);
+               p2p_dbg(p2p, "Unsupported ANQP vendor type %u", *pos);
                return;
        }
        pos++;
@@ -372,8 +360,7 @@ void p2p_rx_gas_initial_req(struct p2p_data *p2p, const u8 *sa,
        if (pos + 2 > end)
                return;
        update_indic = WPA_GET_LE16(pos);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Service Update Indicator: %u", update_indic);
+       p2p_dbg(p2p, "Service Update Indicator: %u", update_indic);
        pos += 2;
 
        p2p->cfg->sd_request(p2p->cfg->cb_ctx, freq, sa, dialog_token,
@@ -389,8 +376,7 @@ void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
 
        /* TODO: fix the length limit to match with the maximum frame length */
        if (wpabuf_len(resp_tlvs) > 1400) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: SD response long "
-                       "enough to require fragmentation");
+               p2p_dbg(p2p, "SD response long enough to require fragmentation");
                if (p2p->sd_resp) {
                        /*
                         * TODO: Could consider storing the fragmented response
@@ -399,14 +385,12 @@ void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
                         * Though, that would eat more memory, so there are
                         * also benefits to just using a single buffer.
                         */
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Drop "
-                               "previous SD response");
+                       p2p_dbg(p2p, "Drop previous SD response");
                        wpabuf_free(p2p->sd_resp);
                }
                p2p->sd_resp = wpabuf_dup(resp_tlvs);
                if (p2p->sd_resp == NULL) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_ERROR, "P2P: Failed to "
-                               "allocate SD response fragmentation area");
+                       p2p_err(p2p, "Failed to allocate SD response fragmentation area");
                        return;
                }
                os_memcpy(p2p->sd_resp_addr, dst, ETH_ALEN);
@@ -416,8 +400,7 @@ void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
                resp = p2p_build_sd_response(dialog_token, WLAN_STATUS_SUCCESS,
                                             1, p2p->srv_update_indic, NULL);
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: SD response fits "
-                       "in initial response");
+               p2p_dbg(p2p, "SD response fits in initial response");
                resp = p2p_build_sd_response(dialog_token,
                                             WLAN_STATUS_SUCCESS, 0,
                                             p2p->srv_update_indic, resp_tlvs);
@@ -429,8 +412,7 @@ void p2p_sd_response(struct p2p_data *p2p, int freq, const u8 *dst,
        if (p2p_send_action(p2p, freq, dst, 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");
+               p2p_dbg(p2p, "Failed to send Action frame");
 
        wpabuf_free(resp);
 }
@@ -450,8 +432,7 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
 
 #ifdef ANDROID_P2P
        if (p2p->state != P2P_SD_DURING_FIND) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: #### Not ignoring unexpected GAS Initial Response from "
+               p2p_dbg(p2p, "P2P: #### Not ignoring unexpected GAS Initial Response from "
                        MACSTR " state %d", MAC2STR(sa), p2p->state);
        }
        if (p2p->sd_peer == NULL ||
@@ -459,21 +440,18 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
 #endif
            os_memcmp(sa, p2p->sd_peer->info.p2p_device_addr, ETH_ALEN) != 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore unexpected GAS Initial Response from "
+               p2p_dbg(p2p, "Ignore unexpected GAS Initial Response from "
                        MACSTR, MAC2STR(sa));
                return;
        }
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
        p2p_clear_timeout(p2p);
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received GAS Initial Response from " MACSTR " (len=%d)",
+       p2p_dbg(p2p, "Received GAS Initial Response from " MACSTR " (len=%d)",
                MAC2STR(sa), (int) len);
 
        if (len < 5 + 2) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Too short GAS Initial Response frame");
+               p2p_dbg(p2p, "Too short GAS Initial Response frame");
                return;
        }
 
@@ -483,20 +461,16 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        pos += 2;
        comeback_delay = WPA_GET_LE16(pos);
        pos += 2;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: dialog_token=%u status_code=%u comeback_delay=%u",
+       p2p_dbg(p2p, "dialog_token=%u status_code=%u comeback_delay=%u",
                dialog_token, status_code, comeback_delay);
        if (status_code) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Service Discovery failed: status code %u",
+               p2p_dbg(p2p, "Service Discovery failed: status code %u",
                        status_code);
                return;
        }
 
        if (*pos != WLAN_EID_ADV_PROTO) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected IE in GAS Initial Response: %u",
-                       *pos);
+               p2p_dbg(p2p, "Unexpected IE in GAS Initial Response: %u", *pos);
                return;
        }
        pos++;
@@ -504,15 +478,13 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        slen = *pos++;
        next = pos + slen;
        if (next > end || slen < 2) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid IE in GAS Initial Response");
+               p2p_dbg(p2p, "Invalid IE in GAS Initial Response");
                return;
        }
        pos++; /* skip QueryRespLenLimit and PAME-BI */
 
        if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported GAS advertisement protocol id %u",
+               p2p_dbg(p2p, "Unsupported GAS advertisement protocol id %u",
                        *pos);
                return;
        }
@@ -520,27 +492,22 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        pos = next;
        /* Query Response */
        if (pos + 2 > end) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too short Query "
-                       "Response");
+               p2p_dbg(p2p, "Too short Query Response");
                return;
        }
        slen = WPA_GET_LE16(pos);
        pos += 2;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Query Response Length: %d",
-               slen);
+       p2p_dbg(p2p, "Query Response Length: %d", slen);
        if (pos + slen > end) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Not enough Query "
-                       "Response data");
+               p2p_dbg(p2p, "Not enough Query Response data");
                return;
        }
        end = pos + slen;
 
        if (comeback_delay) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Fragmented "
-                       "response - request fragments");
+               p2p_dbg(p2p, "Fragmented response - request fragments");
                if (p2p->sd_rx_resp) {
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Drop "
-                               "old SD reassembly buffer");
+                       p2p_dbg(p2p, "Drop old SD reassembly buffer");
                        wpabuf_free(p2p->sd_rx_resp);
                        p2p->sd_rx_resp = NULL;
                }
@@ -552,8 +519,7 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        if (pos + 4 > end)
                return;
        if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
+               p2p_dbg(p2p, "Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
                return;
        }
        pos += 2;
@@ -561,21 +527,18 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        slen = WPA_GET_LE16(pos);
        pos += 2;
        if (pos + slen > end || slen < 3 + 1) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid ANQP Query Response length");
+               p2p_dbg(p2p, "Invalid ANQP Query Response length");
                return;
        }
 
        if (WPA_GET_BE24(pos) != OUI_WFA) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
+               p2p_dbg(p2p, "Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
                return;
        }
        pos += 3;
 
        if (*pos != P2P_OUI_TYPE) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP vendor type %u", *pos);
+               p2p_dbg(p2p, "Unsupported ANQP vendor type %u", *pos);
                return;
        }
        pos++;
@@ -583,8 +546,7 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        if (pos + 2 > end)
                return;
        update_indic = WPA_GET_LE16(pos);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Service Update Indicator: %u", update_indic);
+       p2p_dbg(p2p, "Service Update Indicator: %u", update_indic);
        pos += 2;
 
        p2p->sd_peer->flags |= P2P_DEV_SD_INFO;
@@ -594,8 +556,7 @@ void p2p_rx_gas_initial_resp(struct p2p_data *p2p, const u8 *sa,
        if (p2p->sd_query) {
                if (!p2p->sd_query->for_all_peers) {
                        struct p2p_sd_query *q;
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Remove completed SD query %p",
+                       p2p_dbg(p2p, "Remove completed SD query %p",
                                p2p->sd_query);
                        q = p2p->sd_query;
                        p2p_unlink_sd_query(p2p, p2p->sd_query);
@@ -623,22 +584,20 @@ void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
        if (len < 1)
                return;
        dialog_token = *data;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Dialog Token: %u",
-               dialog_token);
+       p2p_dbg(p2p, "Dialog Token: %u", dialog_token);
        if (dialog_token != p2p->sd_resp_dialog_token) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
-                       "response fragment for dialog token %u", dialog_token);
+               p2p_dbg(p2p, "No pending SD response fragment for dialog token %u",
+                       dialog_token);
                return;
        }
 
        if (p2p->sd_resp == NULL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
-                       "response fragment available");
+               p2p_dbg(p2p, "No pending SD response fragment available");
                return;
        }
        if (os_memcmp(sa, p2p->sd_resp_addr, ETH_ALEN) != 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No pending SD "
-                       "response fragment for " MACSTR, MAC2STR(sa));
+               p2p_dbg(p2p, "No pending SD response fragment for " MACSTR,
+                       MAC2STR(sa));
                return;
        }
 
@@ -655,19 +614,16 @@ void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
                                           wpabuf_len(p2p->sd_resp));
        if (resp == NULL)
                return;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Send GAS Comeback "
-               "Response (frag_id %d more=%d frag_len=%d)",
+       p2p_dbg(p2p, "Send GAS Comeback Response (frag_id %d more=%d frag_len=%d)",
                p2p->sd_frag_id, more, (int) frag_len);
        p2p->sd_frag_id++;
        p2p->sd_resp_pos += frag_len;
 
        if (more) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: %d more bytes "
-                       "remain to be sent",
+               p2p_dbg(p2p, "%d more bytes remain to be sent",
                        (int) (wpabuf_len(p2p->sd_resp) - p2p->sd_resp_pos));
        } else {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: All fragments of "
-                       "SD response sent");
+               p2p_dbg(p2p, "All fragments of SD response sent");
                wpabuf_free(p2p->sd_resp);
                p2p->sd_resp = NULL;
        }
@@ -676,8 +632,7 @@ void p2p_rx_gas_comeback_req(struct p2p_data *p2p, const u8 *sa,
        if (p2p_send_action(p2p, rx_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");
+               p2p_dbg(p2p, "Failed to send Action frame");
 
        wpabuf_free(resp);
 }
@@ -700,8 +655,7 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
 
 #ifdef ANDROID_P2P
        if (p2p->state != P2P_SD_DURING_FIND) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: #### Not ignoring unexpected GAS Comeback Response from "
+               p2p_dbg(p2p, "P2P: #### Not ignoring unexpected GAS Comeback Response from "
                        MACSTR " state %d", MAC2STR(sa), p2p->state);
        }
        if (p2p->sd_peer == NULL ||
@@ -709,21 +663,18 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
        if (p2p->state != P2P_SD_DURING_FIND || p2p->sd_peer == NULL ||
 #endif
            os_memcmp(sa, p2p->sd_peer->info.p2p_device_addr, ETH_ALEN) != 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Ignore unexpected GAS Comeback Response from "
+               p2p_dbg(p2p, "Ignore unexpected GAS Comeback Response from "
                        MACSTR, MAC2STR(sa));
                return;
        }
        p2p->cfg->send_action_done(p2p->cfg->cb_ctx);
        p2p_clear_timeout(p2p);
 
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Received GAS Comeback Response from " MACSTR " (len=%d)",
+       p2p_dbg(p2p, "Received GAS Comeback Response from " MACSTR " (len=%d)",
                MAC2STR(sa), (int) len);
 
        if (len < 6 + 2) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Too short GAS Comeback Response frame");
+               p2p_dbg(p2p, "Too short GAS Comeback Response frame");
                return;
        }
 
@@ -736,22 +687,19 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
        pos++;
        comeback_delay = WPA_GET_LE16(pos);
        pos += 2;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: dialog_token=%u status_code=%u frag_id=%d more_frags=%d "
+       p2p_dbg(p2p, "dialog_token=%u status_code=%u frag_id=%d more_frags=%d "
                "comeback_delay=%u",
                dialog_token, status_code, frag_id, more_frags,
                comeback_delay);
        /* TODO: check frag_id match */
        if (status_code) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Service Discovery failed: status code %u",
+               p2p_dbg(p2p, "Service Discovery failed: status code %u",
                        status_code);
                return;
        }
 
        if (*pos != WLAN_EID_ADV_PROTO) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unexpected IE in GAS Comeback Response: %u",
+               p2p_dbg(p2p, "Unexpected IE in GAS Comeback Response: %u",
                        *pos);
                return;
        }
@@ -760,15 +708,13 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
        slen = *pos++;
        next = pos + slen;
        if (next > end || slen < 2) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid IE in GAS Comeback Response");
+               p2p_dbg(p2p, "Invalid IE in GAS Comeback Response");
                return;
        }
        pos++; /* skip QueryRespLenLimit and PAME-BI */
 
        if (*pos != ACCESS_NETWORK_QUERY_PROTOCOL) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported GAS advertisement protocol id %u",
+               p2p_dbg(p2p, "Unsupported GAS advertisement protocol id %u",
                        *pos);
                return;
        }
@@ -776,22 +722,18 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
        pos = next;
        /* Query Response */
        if (pos + 2 > end) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too short Query "
-                       "Response");
+               p2p_dbg(p2p, "Too short Query Response");
                return;
        }
        slen = WPA_GET_LE16(pos);
        pos += 2;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Query Response Length: %d",
-               slen);
+       p2p_dbg(p2p, "Query Response Length: %d", slen);
        if (pos + slen > end) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Not enough Query "
-                       "Response data");
+               p2p_dbg(p2p, "Not enough Query Response data");
                return;
        }
        if (slen == 0) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: No Query Response "
-                       "data");
+               p2p_dbg(p2p, "No Query Response data");
                return;
        }
        end = pos + slen;
@@ -808,34 +750,29 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
        if (pos + 4 > end)
                return;
        if (WPA_GET_LE16(pos) != ANQP_VENDOR_SPECIFIC) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
+               p2p_dbg(p2p, "Unsupported ANQP Info ID %u", WPA_GET_LE16(pos));
                return;
        }
        pos += 2;
 
        slen = WPA_GET_LE16(pos);
        pos += 2;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: ANQP Query Response "
-               "length: %u", slen);
+       p2p_dbg(p2p, "ANQP Query Response length: %u", slen);
        if (slen < 3 + 1) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Invalid ANQP Query Response length");
+               p2p_dbg(p2p, "Invalid ANQP Query Response length");
                return;
        }
        if (pos + 4 > end)
                return;
 
        if (WPA_GET_BE24(pos) != OUI_WFA) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
+               p2p_dbg(p2p, "Unsupported ANQP OUI %06x", WPA_GET_BE24(pos));
                return;
        }
        pos += 3;
 
        if (*pos != P2P_OUI_TYPE) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Unsupported ANQP vendor type %u", *pos);
+               p2p_dbg(p2p, "Unsupported ANQP vendor type %u", *pos);
                return;
        }
        pos++;
@@ -843,27 +780,23 @@ void p2p_rx_gas_comeback_resp(struct p2p_data *p2p, const u8 *sa,
        if (pos + 2 > end)
                return;
        p2p->sd_rx_update_indic = WPA_GET_LE16(pos);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-               "P2P: Service Update Indicator: %u", p2p->sd_rx_update_indic);
+       p2p_dbg(p2p, "Service Update Indicator: %u", p2p->sd_rx_update_indic);
        pos += 2;
 
 skip_nqp_header:
        if (wpabuf_resize(&p2p->sd_rx_resp, end - pos) < 0)
                return;
        wpabuf_put_data(p2p->sd_rx_resp, pos, end - pos);
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Current SD reassembly "
-               "buffer length: %u",
+       p2p_dbg(p2p, "Current SD reassembly buffer length: %u",
                (unsigned int) wpabuf_len(p2p->sd_rx_resp));
 
        if (more_frags) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: More fragments "
-                       "remains");
+               p2p_dbg(p2p, "More fragments remains");
                /* TODO: what would be a good size limit? */
                if (wpabuf_len(p2p->sd_rx_resp) > 64000) {
                        wpabuf_free(p2p->sd_rx_resp);
                        p2p->sd_rx_resp = NULL;
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Too long "
-                               "SD response - drop it");
+                       p2p_dbg(p2p, "Too long SD response - drop it");
                        return;
                }
                p2p_send_gas_comeback_req(p2p, sa, dialog_token, rx_freq);
@@ -877,8 +810,7 @@ skip_nqp_header:
        if (p2p->sd_query) {
                if (!p2p->sd_query->for_all_peers) {
                        struct p2p_sd_query *q;
-                       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                               "P2P: Remove completed SD query %p",
+                       p2p_dbg(p2p, "Remove completed SD query %p",
                                p2p->sd_query);
                        q = p2p->sd_query;
                        p2p_unlink_sd_query(p2p, p2p->sd_query);
@@ -934,7 +866,7 @@ void * p2p_sd_request(struct p2p_data *p2p, const u8 *dst,
 
        q->next = p2p->sd_queries;
        p2p->sd_queries = q;
-       wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Added SD Query %p", q);
+       p2p_dbg(p2p, "Added SD Query %p", q);
 
        if (dst == NULL) {
                struct p2p_device *dev;
@@ -992,8 +924,7 @@ void p2p_sd_service_update(struct p2p_data *p2p)
 int p2p_sd_cancel_request(struct p2p_data *p2p, void *req)
 {
        if (p2p_unlink_sd_query(p2p, req)) {
-               wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG,
-                       "P2P: Cancel pending SD query %p", req);
+               p2p_dbg(p2p, "Cancel pending SD query %p", req);
 #ifdef ANDROID_P2P
                p2p->sd_dev_list = NULL;
 #endif
index 5511ef1..38ea8aa 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wpa_supplicant/hostapd / Debug prints
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -620,7 +620,7 @@ void wpa_msg(void *ctx, int level, const char *fmt, ...)
        va_end(ap);
        wpa_printf(level, "%s%s", prefix, buf);
        if (wpa_msg_cb)
-               wpa_msg_cb(ctx, level, buf, len);
+               wpa_msg_cb(ctx, level, 0, buf, len);
        os_free(buf);
 }
 
@@ -644,9 +644,56 @@ void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
        va_start(ap, fmt);
        len = vsnprintf(buf, buflen, fmt, ap);
        va_end(ap);
-       wpa_msg_cb(ctx, level, buf, len);
+       wpa_msg_cb(ctx, level, 0, buf, len);
        os_free(buf);
 }
+
+
+void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
+{
+       va_list ap;
+       char *buf;
+       const int buflen = 2048;
+       int len;
+
+       buf = os_malloc(buflen);
+       if (buf == NULL) {
+               wpa_printf(MSG_ERROR, "wpa_msg_global: Failed to allocate "
+                          "message buffer");
+               return;
+       }
+       va_start(ap, fmt);
+       len = vsnprintf(buf, buflen, fmt, ap);
+       va_end(ap);
+       wpa_printf(level, "%s", buf);
+       if (wpa_msg_cb)
+               wpa_msg_cb(ctx, level, 1, buf, len);
+       os_free(buf);
+}
+
+
+void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
+{
+       va_list ap;
+       char *buf;
+       const int buflen = 2048;
+       int len;
+
+       buf = os_malloc(buflen);
+       if (buf == NULL) {
+               wpa_printf(MSG_ERROR, "wpa_msg_no_global: Failed to allocate "
+                          "message buffer");
+               return;
+       }
+       va_start(ap, fmt);
+       len = vsnprintf(buf, buflen, fmt, ap);
+       va_end(ap);
+       wpa_printf(level, "%s", buf);
+       if (wpa_msg_cb)
+               wpa_msg_cb(ctx, level, 2, buf, len);
+       os_free(buf);
+}
+
 #endif /* CONFIG_NO_WPA_MSG */
 
 
index 339c749..2ed1bd8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * wpa_supplicant/hostapd / Debug prints
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -155,6 +155,8 @@ void wpa_hexdump_ascii_key(int level, const char *title, const u8 *buf,
 #ifdef CONFIG_NO_WPA_MSG
 #define wpa_msg(args...) do { } while (0)
 #define wpa_msg_ctrl(args...) do { } while (0)
+#define wpa_msg_global(args...) do { } while (0)
+#define wpa_msg_no_global(args...) do { } while (0)
 #define wpa_msg_register_cb(f) do { } while (0)
 #define wpa_msg_register_ifname_cb(f) do { } while (0)
 #else /* CONFIG_NO_WPA_MSG */
@@ -189,8 +191,38 @@ void wpa_msg(void *ctx, int level, const char *fmt, ...) PRINTF_FORMAT(3, 4);
 void wpa_msg_ctrl(void *ctx, int level, const char *fmt, ...)
 PRINTF_FORMAT(3, 4);
 
-typedef void (*wpa_msg_cb_func)(void *ctx, int level, const char *txt,
-                               size_t len);
+/**
+ * wpa_msg_global - Global printf for ctrl_iface monitors
+ * @ctx: Pointer to context data; this is the ctx variable registered
+ *     with struct wpa_driver_ops::init()
+ * @level: priority level (MSG_*) of the message
+ * @fmt: printf format string, followed by optional arguments
+ *
+ * This function is used to print conditional debugging and error messages.
+ * This function is like wpa_msg(), but it sends the output as a global event,
+ * i.e., without being specific to an interface. For backwards compatibility,
+ * an old style event is also delivered on one of the interfaces (the one
+ * specified by the context data).
+ */
+void wpa_msg_global(void *ctx, int level, const char *fmt, ...)
+PRINTF_FORMAT(3, 4);
+
+/**
+ * wpa_msg_no_global - Conditional printf for ctrl_iface monitors
+ * @ctx: Pointer to context data; this is the ctx variable registered
+ *     with struct wpa_driver_ops::init()
+ * @level: priority level (MSG_*) of the message
+ * @fmt: printf format string, followed by optional arguments
+ *
+ * This function is used to print conditional debugging and error messages.
+ * This function is like wpa_msg(), but it does not send the output as a global
+ * event.
+ */
+void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
+PRINTF_FORMAT(3, 4);
+
+typedef void (*wpa_msg_cb_func)(void *ctx, int level, int global,
+                               const char *txt, size_t len);
 
 /**
  * wpa_msg_register_cb - Register callback function for wpa_msg() messages
index f439632..78df89e 100644 (file)
@@ -410,6 +410,7 @@ Command line options
 
 usage:
   wpa_supplicant [-BddfhKLqqtuvwW] [-P<pid file>] [-g<global ctrl>] \
+        [-G<group>] \
         -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
         [-b<br_ifname> [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
         [-p<driver_param>] [-b<br_ifname>] ...]
@@ -424,6 +425,7 @@ options:
   -D = driver name (can be multiple drivers: nl80211,wext)
   -f = Log output to default log location (normally /tmp)
   -g = global ctrl_interface
+  -G = global ctrl_interface group
   -K = include keys (passwords, etc.) in debug output
   -t = include timestamp in debug messages
   -h = show this help text
index e8bfe0c..6b5dc3f 100644 (file)
@@ -461,6 +461,14 @@ static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
                        return -1;
                return res;
 #endif /* CONFIG_WIFI_DISPLAY */
+#ifdef CONFIG_TESTING_GET_GTK
+       } else if (os_strcmp(cmd, "gtk") == 0) {
+               if (wpa_s->last_gtk_len == 0)
+                       return -1;
+               res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
+                                      wpa_s->last_gtk_len);
+               return res;
+#endif /* CONFIG_TESTING_GET_GTK */
        }
 
        if (res < 0 || (unsigned int) res >= buflen)
@@ -5840,6 +5848,126 @@ static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
 }
 
 
+static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
+                                           const char *ifname,
+                                           char *cmd, size_t *resp_len)
+{
+       struct wpa_supplicant *wpa_s;
+
+       for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
+               if (os_strcmp(ifname, wpa_s->ifname) == 0)
+                       break;
+       }
+
+       if (wpa_s == NULL) {
+               char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
+               if (resp)
+                       *resp_len = os_strlen(resp);
+               else
+                       *resp_len = 1;
+               return resp;
+       }
+
+       return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
+}
+
+
+static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
+                                              char *buf, size_t *resp_len)
+{
+#ifdef CONFIG_P2P
+       static const char * cmd[] = {
+               "P2P_FIND",
+               "P2P_STOP_FIND",
+               "P2P_LISTEN",
+               "P2P_GROUP_ADD",
+               "P2P_GET_PASSPHRASE",
+               "P2P_SERVICE_UPDATE",
+               "P2P_SERVICE_FLUSH",
+               "P2P_FLUSH",
+               "P2P_CANCEL",
+               "P2P_PRESENCE_REQ",
+               "P2P_EXT_LISTEN",
+               NULL
+       };
+       static const char * prefix[] = {
+               "P2P_FIND ",
+               "P2P_CONNECT ",
+               "P2P_LISTEN ",
+               "P2P_GROUP_REMOVE ",
+               "P2P_GROUP_ADD ",
+               "P2P_PROV_DISC ",
+               "P2P_SERV_DISC_REQ ",
+               "P2P_SERV_DISC_CANCEL_REQ ",
+               "P2P_SERV_DISC_RESP ",
+               "P2P_SERV_DISC_EXTERNAL ",
+               "P2P_SERVICE_ADD ",
+               "P2P_SERVICE_DEL ",
+               "P2P_REJECT ",
+               "P2P_INVITE ",
+               "P2P_PEER ",
+               "P2P_SET ",
+               "P2P_UNAUTHORIZE ",
+               "P2P_PRESENCE_REQ ",
+               "P2P_EXT_LISTEN ",
+               NULL
+       };
+       int found = 0;
+       int i;
+
+       if (global->p2p_init_wpa_s == NULL)
+               return NULL;
+
+       for (i = 0; !found && cmd[i]; i++) {
+               if (os_strcmp(buf, cmd[i]) == 0)
+                       found = 1;
+       }
+
+       for (i = 0; !found && prefix[i]; i++) {
+               if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
+                       found = 1;
+       }
+
+       if (found)
+               return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
+                                                        buf, resp_len);
+#endif /* CONFIG_P2P */
+       return NULL;
+}
+
+
+static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
+                                              char *buf, size_t *resp_len)
+{
+#ifdef CONFIG_WIFI_DISPLAY
+       if (global->p2p_init_wpa_s == NULL)
+               return NULL;
+       if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
+           os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
+               return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
+                                                        buf, resp_len);
+#endif /* CONFIG_WIFI_DISPLAY */
+       return NULL;
+}
+
+
+static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
+                                          char *buf, size_t *resp_len)
+{
+       char *ret;
+
+       ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
+       if (ret)
+               return ret;
+
+       ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
+       if (ret)
+               return ret;
+
+       return NULL;
+}
+
+
 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
                                                char *buf, size_t *resp_len)
 {
@@ -5848,6 +5976,20 @@ char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
        int reply_len;
        int level = MSG_DEBUG;
 
+       if (os_strncmp(buf, "IFNAME=", 7) == 0) {
+               char *pos = os_strchr(buf + 7, ' ');
+               if (pos) {
+                       *pos++ = '\0';
+                       return wpas_global_ctrl_iface_ifname(global,
+                                                            buf + 7, pos,
+                                                            resp_len);
+               }
+       }
+
+       reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
+       if (reply)
+               return reply;
+
        if (os_strcmp(buf, "PING") == 0)
                level = MSG_EXCESSIVE;
        wpa_hexdump_ascii(level, "RX global ctrl_iface",
index fd417ff..dc02db2 100644 (file)
@@ -423,7 +423,7 @@ static int ctrl_iface_parse(struct ctrl_iface_priv *priv, const char *params)
 }
 
 
-static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level,
+static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level, int global,
                                             const char *txt, size_t len)
 {
        struct wpa_supplicant *wpa_s = ctx;
index 994f9b1..f3b660d 100644 (file)
@@ -255,7 +255,7 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
 }
 
 
-static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level,
+static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level, int global,
                                             const char *txt, size_t len)
 {
        struct wpa_supplicant *wpa_s = ctx;
index 4dfabc8..545fefd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant / UNIX domain socket -based control interface
- * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -50,12 +50,20 @@ struct ctrl_iface_priv {
 };
 
 
-static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
+struct ctrl_iface_global_priv {
+       struct wpa_global *global;
+       int sock;
+       struct dl_list ctrl_dst;
+};
+
+
+static void wpa_supplicant_ctrl_iface_send(const char *ifname, int sock,
+                                          struct dl_list *ctrl_dst,
                                           int level, const char *buf,
                                           size_t len);
 
 
-static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
+static int wpa_supplicant_ctrl_iface_attach(struct dl_list *ctrl_dst,
                                            struct sockaddr_un *from,
                                            socklen_t fromlen)
 {
@@ -67,7 +75,7 @@ static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
        os_memcpy(&dst->addr, from, sizeof(struct sockaddr_un));
        dst->addrlen = fromlen;
        dst->debug_level = MSG_INFO;
-       dl_list_add(&priv->ctrl_dst, &dst->list);
+       dl_list_add(ctrl_dst, &dst->list);
        wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor attached",
                    (u8 *) from->sun_path,
                    fromlen - offsetof(struct sockaddr_un, sun_path));
@@ -75,13 +83,13 @@ static int wpa_supplicant_ctrl_iface_attach(struct ctrl_iface_priv *priv,
 }
 
 
-static int wpa_supplicant_ctrl_iface_detach(struct ctrl_iface_priv *priv,
+static int wpa_supplicant_ctrl_iface_detach(struct dl_list *ctrl_dst,
                                            struct sockaddr_un *from,
                                            socklen_t fromlen)
 {
        struct wpa_ctrl_dst *dst;
 
-       dl_list_for_each(dst, &priv->ctrl_dst, struct wpa_ctrl_dst, list) {
+       dl_list_for_each(dst, ctrl_dst, struct wpa_ctrl_dst, list) {
                if (fromlen == dst->addrlen &&
                    os_memcmp(from->sun_path, dst->addr.sun_path,
                              fromlen - offsetof(struct sockaddr_un, sun_path))
@@ -148,14 +156,16 @@ static void wpa_supplicant_ctrl_iface_receive(int sock, void *eloop_ctx,
        buf[res] = '\0';
 
        if (os_strcmp(buf, "ATTACH") == 0) {
-               if (wpa_supplicant_ctrl_iface_attach(priv, &from, fromlen))
+               if (wpa_supplicant_ctrl_iface_attach(&priv->ctrl_dst, &from,
+                                                    fromlen))
                        reply_len = 1;
                else {
                        new_attached = 1;
                        reply_len = 2;
                }
        } else if (os_strcmp(buf, "DETACH") == 0) {
-               if (wpa_supplicant_ctrl_iface_detach(priv, &from, fromlen))
+               if (wpa_supplicant_ctrl_iface_detach(&priv->ctrl_dst, &from,
+                                                    fromlen))
                        reply_len = 1;
                else
                        reply_len = 2;
@@ -264,13 +274,30 @@ static char * wpa_supplicant_ctrl_iface_path(struct wpa_supplicant *wpa_s)
 }
 
 
-static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level,
+static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level, int global,
                                             const char *txt, size_t len)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       if (wpa_s == NULL || wpa_s->ctrl_iface == NULL)
+
+       if (wpa_s == NULL)
                return;
-       wpa_supplicant_ctrl_iface_send(wpa_s->ctrl_iface, level, txt, len);
+
+       if (global != 2 && wpa_s->global->ctrl_iface) {
+               struct ctrl_iface_global_priv *priv = wpa_s->global->ctrl_iface;
+               if (!dl_list_empty(&priv->ctrl_dst)) {
+                       wpa_supplicant_ctrl_iface_send(global ? NULL :
+                                                      wpa_s->ifname,
+                                                      priv->sock,
+                                                      &priv->ctrl_dst,
+                                                      level, txt, len);
+               }
+       }
+
+       if (wpa_s->ctrl_iface == NULL)
+               return;
+       wpa_supplicant_ctrl_iface_send(NULL, wpa_s->ctrl_iface->sock,
+                                      &wpa_s->ctrl_iface->ctrl_dst,
+                                      level, txt, len);
 }
 
 
@@ -543,14 +570,17 @@ free_dst:
 
 /**
  * wpa_supplicant_ctrl_iface_send - Send a control interface packet to monitors
- * @priv: Pointer to private data from wpa_supplicant_ctrl_iface_init()
+ * @ifname: Interface name for global control socket or %NULL
+ * @sock: Local socket fd
+ * @ctrl_dst: List of attached listeners
  * @level: Priority level of the message
  * @buf: Message data
  * @len: Message length
  *
  * Send a packet to all monitor programs attached to the control interface.
  */
-static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
+static void wpa_supplicant_ctrl_iface_send(const char *ifname, int sock,
+                                          struct dl_list *ctrl_dst,
                                           int level, const char *buf,
                                           size_t len)
 {
@@ -558,32 +588,45 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
        char levelstr[10];
        int idx, res;
        struct msghdr msg;
-       struct iovec io[2];
+       struct iovec io[5];
 
-       if (priv->sock < 0 || dl_list_empty(&priv->ctrl_dst))
+       if (sock < 0 || dl_list_empty(ctrl_dst))
                return;
 
        res = os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
        if (res < 0 || (size_t) res >= sizeof(levelstr))
                return;
-       io[0].iov_base = levelstr;
-       io[0].iov_len = os_strlen(levelstr);
-       io[1].iov_base = (char *) buf;
-       io[1].iov_len = len;
+       idx = 0;
+       if (ifname) {
+               io[idx].iov_base = "IFNAME=";
+               io[idx].iov_len = 7;
+               idx++;
+               io[idx].iov_base = (char *) ifname;
+               io[idx].iov_len = os_strlen(ifname);
+               idx++;
+               io[idx].iov_base = " ";
+               io[idx].iov_len = 1;
+               idx++;
+       }
+       io[idx].iov_base = levelstr;
+       io[idx].iov_len = os_strlen(levelstr);
+       idx++;
+       io[idx].iov_base = (char *) buf;
+       io[idx].iov_len = len;
+       idx++;
        os_memset(&msg, 0, sizeof(msg));
        msg.msg_iov = io;
-       msg.msg_iovlen = 2;
+       msg.msg_iovlen = idx;
 
        idx = 0;
-       dl_list_for_each_safe(dst, next, &priv->ctrl_dst, struct wpa_ctrl_dst,
-                             list) {
+       dl_list_for_each_safe(dst, next, ctrl_dst, struct wpa_ctrl_dst, list) {
                if (level >= dst->debug_level) {
                        wpa_hexdump(MSG_DEBUG, "CTRL_IFACE monitor send",
                                    (u8 *) dst->addr.sun_path, dst->addrlen -
                                    offsetof(struct sockaddr_un, sun_path));
                        msg.msg_name = (void *) &dst->addr;
                        msg.msg_namelen = dst->addrlen;
-                       if (sendmsg(priv->sock, &msg, 0) < 0) {
+                       if (sendmsg(sock, &msg, 0) < 0) {
                                int _errno = errno;
                                wpa_printf(MSG_INFO, "CTRL_IFACE monitor[%d]: "
                                           "%d - %s",
@@ -593,7 +636,7 @@ static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
                                    (_errno != ENOBUFS && dst->errors > 10) ||
                                    _errno == ENOENT) {
                                        wpa_supplicant_ctrl_iface_detach(
-                                               priv, &dst->addr,
+                                               ctrl_dst, &dst->addr,
                                                dst->addrlen);
                                }
                        } else
@@ -626,8 +669,8 @@ void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
 
                if (os_strcmp(buf, "ATTACH") == 0) {
                        /* handle ATTACH signal of first monitor interface */
-                       if (!wpa_supplicant_ctrl_iface_attach(priv, &from,
-                                                             fromlen)) {
+                       if (!wpa_supplicant_ctrl_iface_attach(&priv->ctrl_dst,
+                                                             &from, fromlen)) {
                                sendto(priv->sock, "OK\n", 3, 0,
                                       (struct sockaddr *) &from, fromlen);
                                /* OK to continue */
@@ -647,21 +690,16 @@ void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
 
 /* Global ctrl_iface */
 
-struct ctrl_iface_global_priv {
-       struct wpa_global *global;
-       int sock;
-};
-
-
 static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
                                                     void *sock_ctx)
 {
        struct wpa_global *global = eloop_ctx;
+       struct ctrl_iface_global_priv *priv = sock_ctx;
        char buf[256];
        int res;
        struct sockaddr_un from;
        socklen_t fromlen = sizeof(from);
-       char *reply;
+       char *reply = NULL;
        size_t reply_len;
 
        res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
@@ -672,16 +710,32 @@ static void wpa_supplicant_global_ctrl_iface_receive(int sock, void *eloop_ctx,
        }
        buf[res] = '\0';
 
-       reply = wpa_supplicant_global_ctrl_iface_process(global, buf,
-                                                        &reply_len);
+       if (os_strcmp(buf, "ATTACH") == 0) {
+               if (wpa_supplicant_ctrl_iface_attach(&priv->ctrl_dst, &from,
+                                                    fromlen))
+                       reply_len = 1;
+               else
+                       reply_len = 2;
+       } else if (os_strcmp(buf, "DETACH") == 0) {
+               if (wpa_supplicant_ctrl_iface_detach(&priv->ctrl_dst, &from,
+                                                    fromlen))
+                       reply_len = 1;
+               else
+                       reply_len = 2;
+       } else {
+               reply = wpa_supplicant_global_ctrl_iface_process(global, buf,
+                                                                &reply_len);
+       }
 
        if (reply) {
                sendto(sock, reply, reply_len, 0, (struct sockaddr *) &from,
                       fromlen);
                os_free(reply);
-       } else if (reply_len) {
+       } else if (reply_len == 1) {
                sendto(sock, "FAIL\n", 5, 0, (struct sockaddr *) &from,
                       fromlen);
+       } else if (reply_len == 2) {
+               sendto(sock, "OK\n", 3, 0, (struct sockaddr *) &from, fromlen);
        }
 }
 
@@ -691,24 +745,48 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
 {
        struct ctrl_iface_global_priv *priv;
        struct sockaddr_un addr;
+       const char *ctrl = global->params.ctrl_interface;
 
        priv = os_zalloc(sizeof(*priv));
        if (priv == NULL)
                return NULL;
+       dl_list_init(&priv->ctrl_dst);
        priv->global = global;
        priv->sock = -1;
 
-       if (global->params.ctrl_interface == NULL)
+       if (ctrl == NULL)
                return priv;
 
+       wpa_printf(MSG_DEBUG, "Global control interface '%s'", ctrl);
+
 #ifdef ANDROID
-       priv->sock = android_get_control_socket(global->params.ctrl_interface);
-       if (priv->sock >= 0)
+       if (os_strncmp(ctrl, "@android:", 9) == 0) {
+               priv->sock = android_get_control_socket(ctrl + 9);
+               if (priv->sock < 0) {
+                       wpa_printf(MSG_ERROR, "Failed to open Android control "
+                                  "socket '%s'", ctrl + 9);
+                       goto fail;
+               }
+               wpa_printf(MSG_DEBUG, "Using Android control socket '%s'",
+                          ctrl + 9);
                goto havesock;
-#endif /* ANDROID */
+       }
 
-       wpa_printf(MSG_DEBUG, "Global control interface '%s'",
-                  global->params.ctrl_interface);
+       if (os_strncmp(ctrl, "@abstract:", 10) != 0) {
+               /*
+                * Backwards compatibility - try to open an Android control
+                * socket and if that fails, assume this was a UNIX domain
+                * socket instead.
+                */
+               priv->sock = android_get_control_socket(ctrl);
+               if (priv->sock >= 0) {
+                       wpa_printf(MSG_DEBUG,
+                                  "Using Android control socket '%s'",
+                                  ctrl);
+                       goto havesock;
+               }
+       }
+#endif /* ANDROID */
 
        priv->sock = socket(PF_UNIX, SOCK_DGRAM, 0);
        if (priv->sock < 0) {
@@ -721,8 +799,23 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
        addr.sun_len = sizeof(addr);
 #endif /* __FreeBSD__ */
        addr.sun_family = AF_UNIX;
-       os_strlcpy(addr.sun_path, global->params.ctrl_interface,
-                  sizeof(addr.sun_path));
+
+       if (os_strncmp(ctrl, "@abstract:", 10) == 0) {
+               addr.sun_path[0] = '\0';
+               os_strlcpy(addr.sun_path + 1, ctrl + 10,
+                          sizeof(addr.sun_path) - 1);
+               if (bind(priv->sock, (struct sockaddr *) &addr, sizeof(addr)) <
+                   0) {
+                       wpa_printf(MSG_ERROR, "supp-global-ctrl-iface-init: "
+                                  "bind(PF_UNIX) failed: %s", strerror(errno));
+                       goto fail;
+               }
+               wpa_printf(MSG_DEBUG, "Using Abstract control socket '%s'",
+                          ctrl + 10);
+               goto havesock;
+       }
+
+       os_strlcpy(addr.sun_path, ctrl, sizeof(addr.sun_path));
        if (bind(priv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
                perror("supp-global-ctrl-iface-init (will try fixup): "
                       "bind(PF_UNIX)");
@@ -731,11 +824,11 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
                        wpa_printf(MSG_DEBUG, "ctrl_iface exists, but does not"
                                   " allow connections - assuming it was left"
                                   "over from forced program termination");
-                       if (unlink(global->params.ctrl_interface) < 0) {
+                       if (unlink(ctrl) < 0) {
                                perror("unlink[ctrl_iface]");
                                wpa_printf(MSG_ERROR, "Could not unlink "
                                           "existing ctrl_iface socket '%s'",
-                                          global->params.ctrl_interface);
+                                          ctrl);
                                goto fail;
                        }
                        if (bind(priv->sock, (struct sockaddr *) &addr,
@@ -745,23 +838,59 @@ wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
                        }
                        wpa_printf(MSG_DEBUG, "Successfully replaced leftover "
                                   "ctrl_iface socket '%s'",
-                                  global->params.ctrl_interface);
+                                  ctrl);
                } else {
                        wpa_printf(MSG_INFO, "ctrl_iface exists and seems to "
                                   "be in use - cannot override it");
                        wpa_printf(MSG_INFO, "Delete '%s' manually if it is "
                                   "not used anymore",
-                                  global->params.ctrl_interface);
+                                  ctrl);
                        goto fail;
                }
        }
 
-#ifdef ANDROID
+       wpa_printf(MSG_DEBUG, "Using UNIX control socket '%s'", ctrl);
+
+       if (global->params.ctrl_interface_group) {
+               char *gid_str = global->params.ctrl_interface_group;
+               gid_t gid = 0;
+               struct group *grp;
+               char *endp;
+
+               grp = getgrnam(gid_str);
+               if (grp) {
+                       gid = grp->gr_gid;
+                       wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
+                                  " (from group name '%s')",
+                                  (int) gid, gid_str);
+               } else {
+                       /* Group name not found - try to parse this as gid */
+                       gid = strtol(gid_str, &endp, 10);
+                       if (*gid_str == '\0' || *endp != '\0') {
+                               wpa_printf(MSG_ERROR, "CTRL: Invalid group "
+                                          "'%s'", gid_str);
+                               goto fail;
+                       }
+                       wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
+                                  (int) gid);
+               }
+               if (chown(ctrl, -1, gid) < 0) {
+                       perror("chown[global_ctrl_interface/ifname]");
+                       goto fail;
+               }
+
+               if (chmod(ctrl, S_IRWXU | S_IRWXG) < 0) {
+                       perror("chmod[global_ctrl_interface/ifname]");
+                       goto fail;
+               }
+       } else {
+               chmod(ctrl, S_IRWXU);
+       }
+
 havesock:
-#endif /* ANDROID */
        eloop_register_read_sock(priv->sock,
                                 wpa_supplicant_global_ctrl_iface_receive,
-                                global, NULL);
+                                global, priv);
 
        return priv;
 
@@ -776,11 +905,16 @@ fail:
 void
 wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
 {
+       struct wpa_ctrl_dst *dst, *prev;
+
        if (priv->sock >= 0) {
                eloop_unregister_read_sock(priv->sock);
                close(priv->sock);
        }
        if (priv->global->params.ctrl_interface)
                unlink(priv->global->params.ctrl_interface);
+       dl_list_for_each_safe(dst, prev, &priv->ctrl_dst, struct wpa_ctrl_dst,
+                             list)
+               os_free(dst);
        os_free(priv);
 }
index 27bcc7a..06a97d3 100644 (file)
@@ -20,7 +20,7 @@
 
 
 /** GAS query timeout in seconds */
-#define GAS_QUERY_TIMEOUT_PERIOD 5
+#define GAS_QUERY_TIMEOUT_PERIOD 2
 
 
 /**
@@ -271,6 +271,11 @@ static void gas_query_rx_comeback(struct gas_query *gas,
        if (frag_id != query->next_frag_id) {
                wpa_printf(MSG_DEBUG, "GAS: Unexpected frag_id in response "
                           "from " MACSTR, MAC2STR(query->addr));
+               if (frag_id + 1 == query->next_frag_id) {
+                       wpa_printf(MSG_DEBUG, "GAS: Drop frame as possible "
+                                  "retry of previous fragment");
+                       return;
+               }
                gas_query_done(gas, query, GAS_QUERY_PEER_ERROR);
                return;
        }
@@ -461,16 +466,20 @@ int gas_query_req(struct gas_query *gas, const u8 *dst, int freq,
 {
        struct gas_query_pending *query;
        int dialog_token;
+       static int next_start = 0;
 
        if (wpabuf_len(req) < 3)
                return -1;
 
        for (dialog_token = 0; dialog_token < 256; dialog_token++) {
-               if (gas_query_dialog_token_available(gas, dst, dialog_token))
+               if (gas_query_dialog_token_available(
+                           gas, dst, (next_start + dialog_token) % 256))
                        break;
        }
        if (dialog_token == 256)
                return -1; /* Too many pending queries */
+       dialog_token = (next_start + dialog_token) % 256;
+       next_start = (dialog_token + 1) % 256;
 
        query = os_zalloc(sizeof(*query));
        if (query == NULL)
index f45c1b7..1b3364c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant / main() function for UNIX like OSes and MinGW
- * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2003-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -25,6 +25,7 @@ static void usage(void)
               "usage:\n"
               "  wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] "
               "[-g<global ctrl>] \\\n"
+              "        [-G<group>] \\\n"
               "        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
               "[-p<driver_param>] \\\n"
               "        [-b<br_ifname>] [-f<debug file>] [-e<entropy file>] "
@@ -59,6 +60,7 @@ static void usage(void)
        printf("  -f = log output to debug file instead of stdout\n");
 #endif /* CONFIG_DEBUG_FILE */
        printf("  -g = global ctrl_interface\n"
+              "  -G = global ctrl_interface group\n"
               "  -K = include keys (passwords, etc.) in debug output\n");
 #ifdef CONFIG_DEBUG_SYSLOG
        printf("  -s = log output to syslog instead of stdout\n");
@@ -157,7 +159,7 @@ int main(int argc, char *argv[])
 
        for (;;) {
                c = getopt(argc, argv,
-                          "b:Bc:C:D:de:f:g:hi:I:KLNo:O:p:P:qsTtuvW");
+                          "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
                if (c < 0)
                        break;
                switch (c) {
@@ -197,6 +199,9 @@ int main(int argc, char *argv[])
                case 'g':
                        params.ctrl_interface = optarg;
                        break;
+               case 'G':
+                       params.ctrl_interface_group = optarg;
+                       break;
                case 'h':
                        usage();
                        exitcode = 0;
index b760e7f..7c19d0c 100644 (file)
@@ -321,9 +321,9 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
                gtype = "GO";
        if (wpa_s->cross_connect_in_use) {
                wpa_s->cross_connect_in_use = 0;
-               wpa_msg(wpa_s->parent, MSG_INFO,
-                       P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
-                       wpa_s->ifname, wpa_s->cross_connect_uplink);
+               wpa_msg_global(wpa_s->parent, MSG_INFO,
+                              P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
+                              wpa_s->ifname, wpa_s->cross_connect_uplink);
        }
        switch (removal_reason) {
        case P2P_GROUP_REMOVAL_REQUESTED:
@@ -351,9 +351,9 @@ static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
                break;
        }
        if (removal_reason != P2P_GROUP_REMOVAL_SILENT) {
-               wpa_msg(wpa_s->parent, MSG_INFO,
-                       P2P_EVENT_GROUP_REMOVED "%s %s%s",
-                       wpa_s->ifname, gtype, reason);
+               wpa_msg_global(wpa_s->parent, MSG_INFO,
+                              P2P_EVENT_GROUP_REMOVED "%s %s%s",
+                              wpa_s->ifname, gtype, reason);
        }
 
 #ifdef ANDROID_P2P
@@ -663,14 +663,15 @@ static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
        wpa_s->p2p_in_provisioning = 0;
 
        if (!success) {
-               wpa_msg(wpa_s->parent, MSG_INFO,
-                       P2P_EVENT_GROUP_FORMATION_FAILURE);
+               wpa_msg_global(wpa_s->parent, MSG_INFO,
+                              P2P_EVENT_GROUP_FORMATION_FAILURE);
                wpas_p2p_group_delete(wpa_s,
                                      P2P_GROUP_REMOVAL_FORMATION_FAILED);
                return;
        }
 
-       wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_FORMATION_SUCCESS);
+       wpa_msg_global(wpa_s->parent, MSG_INFO,
+                      P2P_EVENT_GROUP_FORMATION_SUCCESS);
 
        ssid = wpa_s->current_ssid;
        if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
@@ -717,22 +718,23 @@ static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
        } else if (ssid && ssid->passphrase == NULL && ssid->psk_set) {
                char psk[65];
                wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
-               wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
-                       "%s",
-                       wpa_s->ifname, ssid_txt, ssid->frequency, psk,
-                       MAC2STR(go_dev_addr),
-                       persistent ? " [PERSISTENT]" : "");
+               wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
+                              "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr="
+                              MACSTR "%s",
+                              wpa_s->ifname, ssid_txt, ssid->frequency, psk,
+                              MAC2STR(go_dev_addr),
+                              persistent ? " [PERSISTENT]" : "");
                wpas_p2p_cross_connect_setup(wpa_s);
                wpas_p2p_set_group_idle_timeout(wpa_s);
        } else {
-               wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
-                       "go_dev_addr=" MACSTR "%s",
-                       wpa_s->ifname, ssid_txt, ssid ? ssid->frequency : 0,
-                       ssid && ssid->passphrase ? ssid->passphrase : "",
-                       MAC2STR(go_dev_addr),
-                       persistent ? " [PERSISTENT]" : "");
+               wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
+                              "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
+                              "go_dev_addr=" MACSTR "%s",
+                              wpa_s->ifname, ssid_txt,
+                              ssid ? ssid->frequency : 0,
+                              ssid && ssid->passphrase ? ssid->passphrase : "",
+                              MAC2STR(go_dev_addr),
+                              persistent ? " [PERSISTENT]" : "");
                wpas_p2p_cross_connect_setup(wpa_s);
                wpas_p2p_set_group_idle_timeout(wpa_s);
        }
@@ -855,26 +857,30 @@ static void p2p_go_configured(void *ctx, void *data)
                if (wpa_s->global->p2p_group_formation == wpa_s)
                        wpa_s->global->p2p_group_formation = NULL;
                if (os_strlen(params->passphrase) > 0) {
-                       wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                               "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
-                               "go_dev_addr=" MACSTR "%s", wpa_s->ifname,
-                               wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
-                               ssid->frequency, params->passphrase,
-                               MAC2STR(wpa_s->global->p2p_dev_addr),
-                               params->persistent_group ? " [PERSISTENT]" :
-                               "");
+                       wpa_msg_global(wpa_s->parent, MSG_INFO,
+                                      P2P_EVENT_GROUP_STARTED
+                                      "%s GO ssid=\"%s\" freq=%d "
+                                      "passphrase=\"%s\" go_dev_addr=" MACSTR
+                                      "%s", wpa_s->ifname,
+                                      wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
+                                      ssid->frequency, params->passphrase,
+                                      MAC2STR(wpa_s->global->p2p_dev_addr),
+                                      params->persistent_group ?
+                                      " [PERSISTENT]" : "");
                } else {
                        char psk[65];
                        wpa_snprintf_hex(psk, sizeof(psk), params->psk,
                                         sizeof(params->psk));
-                       wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                               "%s GO ssid=\"%s\" freq=%d psk=%s "
-                               "go_dev_addr=" MACSTR "%s", wpa_s->ifname,
-                               wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
-                               ssid->frequency, psk,
-                               MAC2STR(wpa_s->global->p2p_dev_addr),
-                               params->persistent_group ? " [PERSISTENT]" :
-                               "");
+                       wpa_msg_global(wpa_s->parent, MSG_INFO,
+                                      P2P_EVENT_GROUP_STARTED
+                                      "%s GO ssid=\"%s\" freq=%d psk=%s "
+                                      "go_dev_addr=" MACSTR "%s",
+                                      wpa_s->ifname,
+                                      wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
+                                      ssid->frequency, psk,
+                                      MAC2STR(wpa_s->global->p2p_dev_addr),
+                                      params->persistent_group ?
+                                      " [PERSISTENT]" : "");
                }
 
                if (params->persistent_group)
@@ -948,8 +954,8 @@ static void wpas_start_wps_go(struct wpa_supplicant *wpa_s,
        if (os_strlen(params->passphrase) > 0) {
                ssid->passphrase = os_strdup(params->passphrase);
                if (ssid->passphrase == NULL) {
-                       wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to copy "
-                               "passphrase for GO");
+                       wpa_msg_global(wpa_s, MSG_ERROR,
+                                      "P2P: Failed to copy passphrase for GO");
                        wpa_config_remove_network(wpa_s->conf, ssid->id);
                        return;
                }
@@ -1145,8 +1151,9 @@ void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
        }
 
        if (res->status) {
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_FAILURE "status=%d",
-                       res->status);
+               wpa_msg_global(wpa_s, MSG_INFO,
+                              P2P_EVENT_GO_NEG_FAILURE "status=%d",
+                              res->status);
                wpas_notify_p2p_go_neg_completed(wpa_s, res);
                wpas_p2p_remove_pending_group_interface(wpa_s);
                return;
@@ -1155,7 +1162,7 @@ void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
        if (wpa_s->p2p_go_ht40)
                res->ht40 = 1;
 
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS);
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS);
        wpas_notify_p2p_go_neg_completed(wpa_s, res);
 
        if (res->role_go && wpa_s->p2p_persistent_id >= 0) {
@@ -1215,8 +1222,8 @@ 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)
 {
        struct wpa_supplicant *wpa_s = ctx;
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
-               " dev_passwd_id=%u", MAC2STR(src), dev_passwd_id);
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
+                      " dev_passwd_id=%u", MAC2STR(src), dev_passwd_id);
 
        wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id);
 }
@@ -1239,16 +1246,16 @@ void wpas_dev_found(void *ctx, const u8 *addr,
                                        WFD_DEV_INFO_SIZE);
        }
 #endif /* CONFIG_WIFI_DISPLAY */
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
-               " p2p_dev_addr=" MACSTR
-               " pri_dev_type=%s name='%s' config_methods=0x%x "
-               "dev_capab=0x%x group_capab=0x%x%s%s",
-               MAC2STR(addr), MAC2STR(info->p2p_device_addr),
-               wps_dev_type_bin2str(info->pri_dev_type, devtype,
-                                    sizeof(devtype)),
-               info->device_name, info->config_methods,
-               info->dev_capab, info->group_capab,
-               wfd_dev_info_hex[0] ? " wfd_dev_info=0x" : "", wfd_dev_info_hex);
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
+                      " p2p_dev_addr=" MACSTR
+                      " pri_dev_type=%s name='%s' config_methods=0x%x "
+                      "dev_capab=0x%x group_capab=0x%x%s%s",
+                      MAC2STR(addr), MAC2STR(info->p2p_device_addr),
+                      wps_dev_type_bin2str(info->pri_dev_type, devtype,
+                                           sizeof(devtype)),
+                      info->device_name, info->config_methods,
+                      info->dev_capab, info->group_capab,
+                      wfd_dev_info_hex[0] ? " wfd_dev_info=0x" : "", wfd_dev_info_hex);
 #endif /* CONFIG_NO_STDOUT_DEBUG */
 
        wpas_notify_p2p_device_found(ctx, info->p2p_device_addr, new_device);
@@ -1259,13 +1266,20 @@ static void wpas_dev_lost(void *ctx, const u8 *dev_addr)
 {
        struct wpa_supplicant *wpa_s = ctx;
 
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST
-               "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr));
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST
+                      "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr));
 
        wpas_notify_p2p_device_lost(wpa_s, dev_addr);
 }
 
 
+static void wpas_find_stopped(void *ctx)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED);
+}
+
+
 static int wpas_start_listen(void *ctx, unsigned int freq,
                             unsigned int duration,
                             const struct wpabuf *probe_resp_ie)
@@ -2274,16 +2288,16 @@ static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s,
                                         const u8 *peer, const char *params,
                                         unsigned int generated_pin)
 {
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR " %08d%s",
-               MAC2STR(peer), generated_pin, params);
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
+                      " %08d%s", MAC2STR(peer), generated_pin, params);
 }
 
 
 static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s,
                                        const u8 *peer, const char *params)
 {
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR "%s",
-               MAC2STR(peer), params);
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
+                      "%s", MAC2STR(peer), params);
 }
 
 
@@ -2335,8 +2349,8 @@ void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
        } else if (config_methods & WPS_CONFIG_KEYPAD)
                wpas_prov_disc_local_keypad(wpa_s, peer, params);
        else if (config_methods & WPS_CONFIG_PUSHBUTTON)
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
-                       "%s", MAC2STR(peer), params);
+               wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ
+                              MACSTR "%s", MAC2STR(peer), params);
 
        wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */,
                                            P2P_PROV_DISC_SUCCESS,
@@ -2374,8 +2388,8 @@ void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
                wpas_prov_disc_local_display(wpa_s, peer, params,
                                             generated_pin);
        } else if (config_methods & WPS_CONFIG_PUSHBUTTON)
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR
-                       "%s", MAC2STR(peer), params);
+               wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP
+                              MACSTR "%s", MAC2STR(peer), params);
 
        wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
                                            P2P_PROV_DISC_SUCCESS,
@@ -2404,9 +2418,9 @@ static void wpas_prov_disc_fail(void *ctx, const u8 *peer,
                return;
        }
 
-       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
-               " p2p_dev_addr=" MACSTR " status=%d",
-               MAC2STR(peer), status);
+       wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
+                      " p2p_dev_addr=" MACSTR " status=%d",
+                      MAC2STR(peer), status);
 
        wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
                                            status, 0, 0);
@@ -2557,27 +2571,30 @@ static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
 
        if (!s) {
                if (bssid) {
-                       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
-                               "sa=" MACSTR " go_dev_addr=" MACSTR
-                               " bssid=" MACSTR " unknown-network",
-                               MAC2STR(sa), MAC2STR(go_dev_addr),
-                               MAC2STR(bssid));
+                       wpa_msg_global(wpa_s, MSG_INFO,
+                                      P2P_EVENT_INVITATION_RECEIVED
+                                      "sa=" MACSTR " go_dev_addr=" MACSTR
+                                      " bssid=" MACSTR " unknown-network",
+                                      MAC2STR(sa), MAC2STR(go_dev_addr),
+                                      MAC2STR(bssid));
                } else {
-                       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
-                               "sa=" MACSTR " go_dev_addr=" MACSTR
-                               " unknown-network",
-                               MAC2STR(sa), MAC2STR(go_dev_addr));
+                       wpa_msg_global(wpa_s, MSG_INFO,
+                                      P2P_EVENT_INVITATION_RECEIVED
+                                      "sa=" MACSTR " go_dev_addr=" MACSTR
+                                      " unknown-network",
+                                      MAC2STR(sa), MAC2STR(go_dev_addr));
                }
                return;
        }
 
        if (s->mode == WPAS_MODE_P2P_GO && op_freq) {
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED "sa="
-                       MACSTR " persistent=%d freq=%d",
-                       MAC2STR(sa), s->id, op_freq);
+               wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
+                              "sa=" MACSTR " persistent=%d freq=%d",
+                              MAC2STR(sa), s->id, op_freq);
        } else {
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED "sa="
-                       MACSTR " persistent=%d", MAC2STR(sa), s->id);
+               wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
+                              "sa=" MACSTR " persistent=%d",
+                              MAC2STR(sa), s->id);
        }
 }
 
@@ -2649,12 +2666,12 @@ static void wpas_invitation_result(void *ctx, int status, const u8 *bssid,
        struct wpa_ssid *ssid;
 
        if (bssid) {
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
-                       "status=%d " MACSTR,
-                       status, MAC2STR(bssid));
+               wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
+                              "status=%d " MACSTR,
+                              status, MAC2STR(bssid));
        } else {
-               wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
-                       "status=%d ", status);
+               wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
+                              "status=%d ", status);
        }
        wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
 
@@ -2995,6 +3012,13 @@ static int wpas_go_connected(void *ctx, const u8 *dev_addr)
 }
 
 
+static void wpas_p2p_debug_print(void *ctx, int level, const char *msg)
+{
+       struct wpa_supplicant *wpa_s = ctx;
+       wpa_msg_global(wpa_s, level, "P2P: %s", msg);
+}
+
+
 /**
  * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
  * @global: Pointer to global data from wpa_supplicant_init()
@@ -3033,8 +3057,8 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
        }
 
        os_memset(&p2p, 0, sizeof(p2p));
-       p2p.msg_ctx = wpa_s;
        p2p.cb_ctx = wpa_s;
+       p2p.debug_print = wpas_p2p_debug_print;
        p2p.p2p_scan = wpas_p2p_scan;
        p2p.send_action = wpas_send_action;
        p2p.send_action_done = wpas_send_action_done;
@@ -3042,6 +3066,7 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
        p2p.go_neg_req_rx = wpas_go_neg_req_rx;
        p2p.dev_found = wpas_dev_found;
        p2p.dev_lost = wpas_dev_lost;
+       p2p.find_stopped = wpas_find_stopped;
        p2p.start_listen = wpas_start_listen;
        p2p.stop_listen = wpas_stop_listen;
        p2p.send_probe_resp = wpas_send_probe_resp;
@@ -3338,13 +3363,14 @@ static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
                eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
                if (wpa_s->p2p_auto_pd) {
                        wpa_s->p2p_auto_pd = 0;
-                       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
-                               " p2p_dev_addr=" MACSTR " status=N/A",
-                               MAC2STR(wpa_s->pending_join_dev_addr));
+                       wpa_msg_global(wpa_s, MSG_INFO,
+                                      P2P_EVENT_PROV_DISC_FAILURE
+                                      " p2p_dev_addr=" MACSTR " status=N/A",
+                                      MAC2STR(wpa_s->pending_join_dev_addr));
                        return;
                }
-               wpa_msg(wpa_s->parent, MSG_INFO,
-                       P2P_EVENT_GROUP_FORMATION_FAILURE);
+               wpa_msg_global(wpa_s->parent, MSG_INFO,
+                              P2P_EVENT_GROUP_FORMATION_FAILURE);
        }
 }
 
@@ -3468,9 +3494,10 @@ static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
                                      wpa_s->pending_pd_config_methods, join,
                                      0, wpa_s->user_initiated_pd) < 0) {
                        wpa_s->p2p_auto_pd = 0;
-                       wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
-                               " p2p_dev_addr=" MACSTR " status=N/A",
-                               MAC2STR(wpa_s->pending_join_dev_addr));
+                       wpa_msg_global(wpa_s, MSG_INFO,
+                                      P2P_EVENT_PROV_DISC_FAILURE
+                                      " p2p_dev_addr=" MACSTR " status=N/A",
+                                      MAC2STR(wpa_s->pending_join_dev_addr));
                }
                return;
        }
@@ -3532,9 +3559,9 @@ static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
                u16 method;
 
                if (wpas_check_freq_conflict(wpa_s, freq) > 0) {
-                       wpa_msg(wpa_s->parent, MSG_INFO,
-                               P2P_EVENT_GROUP_FORMATION_FAILURE
-                               "reason=FREQ_CONFLICT");
+                       wpa_msg_global(wpa_s->parent, MSG_INFO,
+                                      P2P_EVENT_GROUP_FORMATION_FAILURE
+                                      "reason=FREQ_CONFLICT");
                        return;
                }
 
@@ -4246,13 +4273,14 @@ wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
 
        if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
                                         WPA_IF_P2P_CLIENT) < 0) {
-               wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to add group interface");
+               wpa_msg_global(wpa_s, MSG_ERROR,
+                              "P2P: Failed to add group interface");
                return NULL;
        }
        group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
        if (group_wpa_s == NULL) {
-               wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to initialize group "
-                       "interface");
+               wpa_msg_global(wpa_s, MSG_ERROR,
+                              "P2P: Failed to initialize group interface");
                wpas_p2p_remove_pending_group_interface(wpa_s);
                return NULL;
        }
@@ -5056,20 +5084,20 @@ void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
        if (ssid->passphrase == NULL && ssid->psk_set) {
                char psk[65];
                wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
-               wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
-                       MACSTR "%s",
-                       wpa_s->ifname, ssid_txt, freq, psk,
-                       MAC2STR(go_dev_addr),
-                       persistent ? " [PERSISTENT]" : "");
+               wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
+                              "%s client ssid=\"%s\" freq=%d psk=%s "
+                              "go_dev_addr=" MACSTR "%s",
+                              wpa_s->ifname, ssid_txt, freq, psk,
+                              MAC2STR(go_dev_addr),
+                              persistent ? " [PERSISTENT]" : "");
        } else {
-               wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
-                       "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
-                       "go_dev_addr=" MACSTR "%s",
-                       wpa_s->ifname, ssid_txt, freq,
-                       ssid->passphrase ? ssid->passphrase : "",
-                       MAC2STR(go_dev_addr),
-                       persistent ? " [PERSISTENT]" : "");
+               wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
+                              "%s client ssid=\"%s\" freq=%d "
+                              "passphrase=\"%s\" go_dev_addr=" MACSTR "%s",
+                              wpa_s->ifname, ssid_txt, freq,
+                              ssid->passphrase ? ssid->passphrase : "",
+                              MAC2STR(go_dev_addr),
+                              persistent ? " [PERSISTENT]" : "");
        }
 
        if (persistent)
@@ -5401,9 +5429,10 @@ int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
 
                        iface->cross_connect_enabled = 0;
                        iface->cross_connect_in_use = 0;
-                       wpa_msg(iface->parent, MSG_INFO,
-                               P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
-                               iface->ifname, iface->cross_connect_uplink);
+                       wpa_msg_global(iface->parent, MSG_INFO,
+                                      P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
+                                      iface->ifname,
+                                      iface->cross_connect_uplink);
                }
        }
 
@@ -5430,9 +5459,9 @@ static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
                        continue;
 
                iface->cross_connect_in_use = 1;
-               wpa_msg(iface->parent, MSG_INFO,
-                       P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
-                       iface->ifname, iface->cross_connect_uplink);
+               wpa_msg_global(iface->parent, MSG_INFO,
+                              P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
+                              iface->ifname, iface->cross_connect_uplink);
        }
 }
 
@@ -5450,9 +5479,9 @@ static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
                if (!iface->cross_connect_in_use)
                        continue;
 
-               wpa_msg(iface->parent, MSG_INFO,
-                       P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
-                       iface->ifname, iface->cross_connect_uplink);
+               wpa_msg_global(iface->parent, MSG_INFO,
+                              P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
+                              iface->ifname, iface->cross_connect_uplink);
                iface->cross_connect_in_use = 0;
        }
 }
@@ -5512,9 +5541,9 @@ static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
                        break;
 
                wpa_s->cross_connect_in_use = 1;
-               wpa_msg(wpa_s->parent, MSG_INFO,
-                       P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
-                       wpa_s->ifname, wpa_s->cross_connect_uplink);
+               wpa_msg_global(wpa_s->parent, MSG_INFO,
+                              P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
+                              wpa_s->ifname, wpa_s->cross_connect_uplink);
                break;
        }
 }
index 04148a8..8cd0f1d 100644 (file)
@@ -527,6 +527,63 @@ static int shared_vif_oper_freq(struct wpa_supplicant *wpa_s)
 }
 
 
+static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
+                                         u16 num_modes,
+                                         enum hostapd_hw_mode mode)
+{
+       u16 i;
+
+       for (i = 0; i < num_modes; i++) {
+               if (modes[i].mode == mode)
+                       return &modes[i];
+       }
+
+       return NULL;
+}
+
+
+static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s,
+                                       enum hostapd_hw_mode band,
+                                       struct wpa_driver_scan_params *params)
+{
+       /* Include only supported channels for the specified band */
+       struct hostapd_hw_modes *mode;
+       int count, i;
+
+       mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band);
+       if (mode == NULL) {
+               /* No channels supported in this band - use empty list */
+               params->freqs = os_zalloc(sizeof(int));
+               return;
+       }
+
+       params->freqs = os_zalloc((mode->num_channels + 1) * sizeof(int));
+       if (params->freqs == NULL)
+               return;
+       for (count = 0, i = 0; i < mode->num_channels; i++) {
+               if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)
+                       continue;
+               params->freqs[count++] = mode->channels[i].freq;
+       }
+}
+
+
+static void wpa_setband_scan_freqs(struct wpa_supplicant *wpa_s,
+                                  struct wpa_driver_scan_params *params)
+{
+       if (wpa_s->hw.modes == NULL)
+               return; /* unknown what channels the driver supports */
+       if (params->freqs)
+               return; /* already using a limited channel set */
+       if (wpa_s->setband == WPA_SETBAND_5G)
+               wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A,
+                                           params);
+       else if (wpa_s->setband == WPA_SETBAND_2G)
+               wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G,
+                                           params);
+}
+
+
 static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
 {
        struct wpa_supplicant *wpa_s = eloop_ctx;
@@ -760,6 +817,7 @@ ssid_list_set:
        } else
                os_free(wpa_s->next_scan_freqs);
        wpa_s->next_scan_freqs = NULL;
+       wpa_setband_scan_freqs(wpa_s, &params);
 
        /* See if user specified frequencies. If so, scan only those. */
        if (wpa_s->conf->freq_list && !params.freqs) {
@@ -1136,6 +1194,8 @@ scan:
                        wpa_s->sched_scan_interval);
        }
 
+       wpa_setband_scan_freqs(wpa_s, scan_params);
+
        ret = wpa_supplicant_start_sched_scan(wpa_s, scan_params,
                                              wpa_s->sched_scan_interval);
        wpabuf_free(extra_ie);
index 61d4b61..966ee83 100644 (file)
@@ -3386,6 +3386,9 @@ static void update_bssid_list(struct wpa_ctrl *ctrl)
 
 static void try_connection(void *eloop_ctx, void *timeout_ctx)
 {
+       if (ctrl_conn)
+               goto done;
+
        if (ctrl_ifname == NULL)
                ctrl_ifname = wpa_cli_get_default_ifname();
 
@@ -3404,6 +3407,7 @@ static void try_connection(void *eloop_ctx, void *timeout_ctx)
        if (warning_displayed)
                printf("Connection established.\n");
 
+done:
        start_edit();
 }
 
@@ -3525,7 +3529,7 @@ static char * wpa_cli_get_default_ifname(void)
 #endif /* CONFIG_CTRL_IFACE_UNIX */
 
 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
-       char buf[2048], *pos;
+       char buf[4096], *pos;
        size_t len;
        struct wpa_ctrl *ctrl;
        int ret;
@@ -3619,6 +3623,23 @@ int main(int argc, char *argv[])
                                global, strerror(errno));
                        return -1;
                }
+
+               if (interactive) {
+                       mon_conn = wpa_ctrl_open(global);
+                       if (mon_conn) {
+                               if (wpa_ctrl_attach(mon_conn) == 0) {
+                                       wpa_cli_attached = 1;
+                                       eloop_register_read_sock(
+                                               wpa_ctrl_get_fd(mon_conn),
+                                               wpa_cli_mon_receive,
+                                               NULL, NULL);
+                               } else {
+                                       printf("Failed to open monitor "
+                                              "connection through global "
+                                              "control interface\n");
+                               }
+                       }
+               }
        }
 
        eloop_register_signal_terminate(wpa_cli_terminate, NULL);
index 1a7c0ff..58605de 100644 (file)
@@ -3309,6 +3309,9 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
        if (params->ctrl_interface)
                global->params.ctrl_interface =
                        os_strdup(params->ctrl_interface);
+       if (params->ctrl_interface_group)
+               global->params.ctrl_interface_group =
+                       os_strdup(params->ctrl_interface_group);
        if (params->override_driver)
                global->params.override_driver =
                        os_strdup(params->override_driver);
@@ -3451,6 +3454,7 @@ void wpa_supplicant_deinit(struct wpa_global *global)
                os_free(global->params.pid_file);
        }
        os_free(global->params.ctrl_interface);
+       os_free(global->params.ctrl_interface_group);
        os_free(global->params.override_driver);
        os_free(global->params.override_ctrl_interface);
 
index a2a189b..c971ae4 100644 (file)
@@ -155,6 +155,11 @@ struct wpa_params {
        char *ctrl_interface;
 
        /**
+        * ctrl_interface_group - Global ctrl_iface group
+        */
+       char *ctrl_interface_group;
+
+       /**
         * dbus_ctrl_interface - Enable the DBus control interface
         */
        int dbus_ctrl_interface;
@@ -348,6 +353,8 @@ struct wpa_supplicant {
        struct wpa_ssid_value *disallow_aps_ssid;
        size_t disallow_aps_ssid_count;
 
+       enum { WPA_SETBAND_AUTO, WPA_SETBAND_5G, WPA_SETBAND_2G } setband;
+
        /* previous scan was wildcard when interleaving between
         * wildcard scans and specific SSID scan when max_ssids=1 */
        int prev_scan_wildcard;
@@ -701,6 +708,11 @@ struct wpa_supplicant {
        u8 wnm_bss_termination_duration[12];
        struct neighbor_report *wnm_neighbor_report_elements;
 #endif /* CONFIG_WNM */
+
+#ifdef CONFIG_TESTING_GET_GTK
+       u8 last_gtk[32];
+       size_t last_gtk_len;
+#endif /* CONFIG_TESTING_GET_GTK */
 };
 
 
index 1a64df3..40720c5 100644 (file)
@@ -437,6 +437,13 @@ static int wpa_supplicant_set_key(void *_wpa_s, enum wpa_alg alg,
                /* Clear the MIC error counter when setting a new PTK. */
                wpa_s->mic_errors_seen = 0;
        }
+#ifdef CONFIG_TESTING_GET_GTK
+       if (key_idx > 0 && addr && is_broadcast_ether_addr(addr) &&
+           alg != WPA_ALG_NONE && key_len <= sizeof(wpa_s->last_gtk)) {
+               os_memcpy(wpa_s->last_gtk, key, key_len);
+               wpa_s->last_gtk_len = key_len;
+       }
+#endif /* CONFIG_TESTING_GET_GTK */
        return wpa_drv_set_key(wpa_s, alg, addr, key_idx, set_tx, seq, seq_len,
                               key, key_len);
 }