[RFC 02/13] nl80211: Convert some wpa_printf to wpa_msg methods.

Dan Williams dcbw
Tue Oct 18 08:05:45 PDT 2011


On Fri, 2011-10-14 at 15:34 -0700, greearb at candelatech.com wrote:
> From: Ben Greear <greearb at candelatech.com>
> 
> This helps debugging when you have multiple interfaces
> handled by a single process.

These do get sent to the control interface and pushed to wpa_cli, is
that what you want?

Dan

> Signed-off-by: Ben Greear <greearb at candelatech.com>
> ---
> :100644 100644 e9369da... 1e34009... M	src/drivers/driver_nl80211.c
>  src/drivers/driver_nl80211.c |  162 +++++++++++++++++++++---------------------
>  1 files changed, 82 insertions(+), 80 deletions(-)
> 
> diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
> index e9369da..1e34009 100644
> --- a/src/drivers/driver_nl80211.c
> +++ b/src/drivers/driver_nl80211.c
> @@ -425,10 +425,10 @@ static void wpa_driver_nl80211_event_link(struct wpa_driver_nl80211_data *drv,
>  	event.interface_status.ievent = del ? EVENT_INTERFACE_REMOVED :
>  		EVENT_INTERFACE_ADDED;
>  
> -	wpa_printf(MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
> -		   del ? "DEL" : "NEW",
> -		   event.interface_status.ifname,
> -		   del ? "removed" : "added");
> +	wpa_msg(drv->ctx, MSG_DEBUG, "RTM_%sLINK, IFLA_IFNAME: Interface '%s' %s",
> +		del ? "DEL" : "NEW",
> +		event.interface_status.ifname,
> +		del ? "removed" : "added");
>  
>  	if (os_strcmp(drv->first_bss.ifname, event.interface_status.ifname) == 0) {
>  		if (del)
> @@ -474,8 +474,8 @@ static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
>  
>  	if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
>  		drv->first_bss.ifindex = if_nametoindex(drv->first_bss.ifname);
> -		wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
> -			   "interface");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Update ifindex for a removed "
> +			"interface");
>  		wpa_driver_nl80211_finish_drv_init(drv);
>  		return 1;
>  	}
> @@ -505,24 +505,24 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
>  	}
>  
>  	if (!drv) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Ignore event for foreign "
> -			   "ifindex %d", ifi->ifi_index);
> +		wpa_msg(NULL, MSG_DEBUG, "nl80211: Ignore event for foreign "
> +			"ifindex %d", ifi->ifi_index);
>  		return;
>  	}
>  
> -	wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
> -		   "(%s%s%s%s)",
> -		   drv->operstate, ifi->ifi_flags,
> -		   (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
> -		   (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
> -		   (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
> -		   (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
> +	wpa_msg(drv->ctx, MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
> +		"(%s%s%s%s)",
> +		drv->operstate, ifi->ifi_flags,
> +		(ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
> +		(ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
> +		(ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
> +		(ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
>  
>  	if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Interface down");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Interface down");
>  		if (drv->ignore_if_down_event) {
> -			wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
> -				   "event generated by mode change");
> +			wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Ignore interface down "
> +				"event generated by mode change");
>  			drv->ignore_if_down_event = 0;
>  		} else {
>  			drv->if_disabled = 1;
> @@ -532,7 +532,7 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
>  	}
>  
>  	if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Interface up");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Interface up");
>  		drv->if_disabled = 0;
>  		wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
>  	}
> @@ -568,8 +568,8 @@ static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
>  		/* device has been added to bridge */
>  		char namebuf[IFNAMSIZ];
>  		if_indextoname(brid, namebuf);
> -		wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
> -			   brid, namebuf);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
> +			brid, namebuf);
>  		add_ifidx(drv, brid);
>  	}
>  #endif /* HOSTAPD */
> @@ -600,8 +600,8 @@ static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
>  	attr = (struct rtattr *) buf;
>  
>  	if (!drv) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Ignore dellink event for"
> -			   " foreign ifindex %d", ifi->ifi_index);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Ignore dellink event for"
> +			" foreign ifindex %d", ifi->ifi_index);
>  		return;
>  	}
>  
> @@ -622,8 +622,8 @@ static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
>  		/* device has been removed from bridge */
>  		char namebuf[IFNAMSIZ];
>  		if_indextoname(brid, namebuf);
> -		wpa_printf(MSG_DEBUG, "nl80211: Remove ifindex %u for bridge "
> -			   "%s", brid, namebuf);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Remove ifindex %u for bridge "
> +			"%s", brid, namebuf);
>  		del_ifidx(drv, brid);
>  	}
>  #endif /* HOSTAPD */
> @@ -638,8 +638,8 @@ static void mlme_event_auth(struct wpa_driver_nl80211_data *drv,
>  
>  	mgmt = (const struct ieee80211_mgmt *) frame;
>  	if (len < 24 + sizeof(mgmt->u.auth)) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Too short association event "
> -			   "frame");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Too short association event "
> +			"frame");
>  		return;
>  	}
>  
> @@ -698,8 +698,8 @@ static void mlme_event_assoc(struct wpa_driver_nl80211_data *drv,
>  
>  	mgmt = (const struct ieee80211_mgmt *) frame;
>  	if (len < 24 + sizeof(mgmt->u.assoc_resp)) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Too short association event "
> -			   "frame");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Too short association event "
> +			"frame");
>  		return;
>  	}
>  
> @@ -747,8 +747,8 @@ static void mlme_event_connect(struct wpa_driver_nl80211_data *drv,
>  		 * Avoid reporting two association events that would confuse
>  		 * the core code.
>  		 */
> -		wpa_printf(MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) "
> -			   "when using userspace SME", cmd);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Ignore connect event (cmd=%d) "
> +			"when using userspace SME", cmd);
>  		return;
>  	}
>  
> @@ -817,8 +817,8 @@ static void mlme_timeout_event(struct wpa_driver_nl80211_data *drv,
>  	if (nla_len(addr) != ETH_ALEN)
>  		return;
>  
> -	wpa_printf(MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR,
> -		   cmd, MAC2STR((u8 *) nla_data(addr)));
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: MLME event %d; timeout with " MACSTR,
> +		cmd, MAC2STR((u8 *) nla_data(addr)));
>  
>  	if (cmd == NL80211_CMD_AUTHENTICATE)
>  		ev = EVENT_AUTH_TIMED_OUT;
> @@ -842,7 +842,7 @@ static void mlme_event_mgmt(struct wpa_driver_nl80211_data *drv,
>  
>  	mgmt = (const struct ieee80211_mgmt *) frame;
>  	if (len < 24) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Too short action frame");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Too short action frame");
>  		return;
>  	}
>  
> @@ -883,11 +883,11 @@ static void mlme_event_action_tx_status(struct wpa_driver_nl80211_data *drv,
>  		return;
>  
>  	cookie_val = nla_get_u64(cookie);
> -	wpa_printf(MSG_DEBUG, "nl80211: Action TX status: cookie=0%llx%s "
> -		   "(ack=%d)",
> -		   (long long unsigned int) cookie_val,
> -		   cookie_val == drv->send_action_cookie ?
> -		   " (match)" : " (unknown)", ack != NULL);
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Action TX status: cookie=0%llx%s "
> +		"(ack=%d)",
> +		(long long unsigned int) cookie_val,
> +		cookie_val == drv->send_action_cookie ?
> +		" (match)" : " (unknown)", ack != NULL);
>  	if (cookie_val != drv->send_action_cookie)
>  		return;
>  
> @@ -926,9 +926,9 @@ static void mlme_event_deauth_disassoc(struct wpa_driver_nl80211_data *drv,
>  			 * response to a clear_state_mismatch() outgoing
>  			 * deauth.  Don't let it take us offline!
>  			 */
> -			wpa_printf(MSG_DEBUG, "nl80211: Deauth received "
> -				   "from Unknown BSSID " MACSTR " -- ignoring",
> -				   MAC2STR(bssid));
> +			wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Deauth received "
> +				"from Unknown BSSID " MACSTR " -- ignoring",
> +				MAC2STR(bssid));
>  			return;
>  		}
>  	}
> @@ -1006,12 +1006,12 @@ static void mlme_event(struct wpa_driver_nl80211_data *drv,
>  	}
>  
>  	if (frame == NULL) {
> -		wpa_printf(MSG_DEBUG, "nl80211: MLME event %d without frame "
> -			   "data", cmd);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: MLME event %d without frame "
> +			"data", cmd);
>  		return;
>  	}
>  
> -	wpa_printf(MSG_DEBUG, "nl80211: MLME event %d", cmd);
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: MLME event %d", cmd);
>  	wpa_hexdump(MSG_MSGDUMP, "nl80211: MLME event frame",
>  		    nla_data(frame), nla_len(frame));
>  
> @@ -1056,7 +1056,7 @@ static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data *drv,
>  {
>  	union wpa_event_data data;
>  
> -	wpa_printf(MSG_DEBUG, "nl80211: MLME event Michael MIC failure");
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: MLME event Michael MIC failure");
>  	os_memset(&data, 0, sizeof(data));
>  	if (tb[NL80211_ATTR_MAC]) {
>  		wpa_hexdump(MSG_DEBUG, "nl80211: Source MAC address",
> @@ -1072,7 +1072,7 @@ static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data *drv,
>  	if (tb[NL80211_ATTR_KEY_TYPE]) {
>  		enum nl80211_key_type key_type =
>  			nla_get_u32(tb[NL80211_ATTR_KEY_TYPE]);
> -		wpa_printf(MSG_DEBUG, "nl80211: Key Type %d", key_type);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Key Type %d", key_type);
>  		if (key_type == NL80211_KEYTYPE_PAIRWISE)
>  			data.michael_mic_failure.unicast = 1;
>  	} else
> @@ -1080,7 +1080,7 @@ static void mlme_event_michael_mic_failure(struct wpa_driver_nl80211_data *drv,
>  
>  	if (tb[NL80211_ATTR_KEY_IDX]) {
>  		u8 key_id = nla_get_u8(tb[NL80211_ATTR_KEY_IDX]);
> -		wpa_printf(MSG_DEBUG, "nl80211: Key Id %d", key_id);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Key Id %d", key_id);
>  	}
>  
>  	wpa_supplicant_event(drv->ctx, EVENT_MICHAEL_MIC_FAILURE, &data);
> @@ -1091,14 +1091,14 @@ static void mlme_event_join_ibss(struct wpa_driver_nl80211_data *drv,
>  				 struct nlattr *tb[])
>  {
>  	if (tb[NL80211_ATTR_MAC] == NULL) {
> -		wpa_printf(MSG_DEBUG, "nl80211: No address in IBSS joined "
> -			   "event");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: No address in IBSS joined "
> +			"event");
>  		return;
>  	}
>  	os_memcpy(drv->bssid, nla_data(tb[NL80211_ATTR_MAC]), ETH_ALEN);
>  	drv->associated = 1;
> -	wpa_printf(MSG_DEBUG, "nl80211: IBSS " MACSTR " joined",
> -		   MAC2STR(drv->bssid));
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: IBSS " MACSTR " joined",
> +		MAC2STR(drv->bssid));
>  
>  	wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
>  }
> @@ -1131,11 +1131,11 @@ static void mlme_event_remain_on_channel(struct wpa_driver_nl80211_data *drv,
>  	else
>  		cookie = 0;
>  
> -	wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d "
> -		   "freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
> -		   cancel_event, freq, chan_type, duration,
> -		   (long long unsigned int) cookie,
> -		   cookie == drv->remain_on_chan_cookie ? "match" : "unknown");
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Remain-on-channel event (cancel=%d "
> +		"freq=%u channel_type=%u duration=%u cookie=0x%llx (%s))",
> +		cancel_event, freq, chan_type, duration,
> +		(long long unsigned int) cookie,
> +		cookie == drv->remain_on_chan_cookie ? "match" : "unknown");
>  
>  	if (cookie != drv->remain_on_chan_cookie)
>  		return; /* not for us */
> @@ -1279,15 +1279,15 @@ static int get_link_noise(struct nl_msg *msg, void *arg)
>  		  genlmsg_attrlen(gnlh, 0), NULL);
>  
>  	if (!tb[NL80211_ATTR_SURVEY_INFO]) {
> -		wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
> +		wpa_msg(NULL, MSG_DEBUG, "nl80211: survey data missing!");
>  		return NL_SKIP;
>  	}
>  
>  	if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
>  			     tb[NL80211_ATTR_SURVEY_INFO],
>  			     survey_policy)) {
> -		wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
> -			   "attributes!");
> +		wpa_msg(NULL, MSG_DEBUG, "nl80211: failed to parse nested "
> +			"attributes!");
>  		return NL_SKIP;
>  	}
>  
> @@ -1349,7 +1349,7 @@ static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv,
>  	if (tb[NL80211_ATTR_CQM] == NULL ||
>  	    nla_parse_nested(cqm, NL80211_ATTR_CQM_MAX, tb[NL80211_ATTR_CQM],
>  			     cqm_policy)) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Ignore invalid CQM event");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Ignore invalid CQM event");
>  		return;
>  	}
>  
> @@ -1369,12 +1369,12 @@ static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv,
>  	event = nla_get_u32(cqm[NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT]);
>  
>  	if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor "
> -			   "event: RSSI high");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Connection quality monitor "
> +			"event: RSSI high");
>  		ed.signal_change.above_threshold = 1;
>  	} else if (event == NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Connection quality monitor "
> -			   "event: RSSI low");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Connection quality monitor "
> +			"event: RSSI low");
>  		ed.signal_change.above_threshold = 0;
>  	} else
>  		return;
> @@ -1383,15 +1383,15 @@ static void nl80211_cqm_event(struct wpa_driver_nl80211_data *drv,
>  	if (res == 0) {
>  		ed.signal_change.current_signal = sig.current_signal;
>  		ed.signal_change.current_txrate = sig.current_txrate;
> -		wpa_printf(MSG_DEBUG, "nl80211: Signal: %d dBm  txrate: %d",
> -			   sig.current_signal, sig.current_txrate);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Signal: %d dBm  txrate: %d",
> +			sig.current_signal, sig.current_txrate);
>  	}
>  
>  	res = nl80211_get_link_noise(drv, &sig);
>  	if (res == 0) {
>  		ed.signal_change.current_noise = sig.current_noise;
> -		wpa_printf(MSG_DEBUG, "nl80211: Noise: %d dBm",
> -			   sig.current_noise);
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Noise: %d dBm",
> +			sig.current_noise);
>  	}
>  
>  	wpa_supplicant_event(drv->ctx, EVENT_SIGNAL_CHANGE, &ed);
> @@ -1407,7 +1407,7 @@ static void nl80211_new_station_event(struct wpa_driver_nl80211_data *drv,
>  	if (tb[NL80211_ATTR_MAC] == NULL)
>  		return;
>  	addr = nla_data(tb[NL80211_ATTR_MAC]);
> -	wpa_printf(MSG_DEBUG, "nl80211: New station " MACSTR, MAC2STR(addr));
> +	wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: New station " MACSTR, MAC2STR(addr));
>  
>  	if (is_ap_interface(drv->nlmode) && drv->no_monitor_iface_capab) {
>  		u8 *ies = NULL;
> @@ -1544,9 +1544,9 @@ static int process_event(struct nl_msg *msg, void *arg)
>  	if (tb[NL80211_ATTR_IFINDEX]) {
>  		int ifindex = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
>  		if (ifindex != drv->ifindex && !have_ifidx(drv, ifindex)) {
> -			wpa_printf(MSG_DEBUG, "nl80211: Ignored event (cmd=%d)"
> -				   " for foreign interface (ifindex %d)",
> -				   gnlh->cmd, ifindex);
> +			wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Ignored event (cmd=%d)"
> +				" for foreign interface (ifindex %d)",
> +				gnlh->cmd, ifindex);
>  			return NL_SKIP;
>  		}
>  	}
> @@ -1561,17 +1561,17 @@ static int process_event(struct nl_msg *msg, void *arg)
>  
>  	switch (gnlh->cmd) {
>  	case NL80211_CMD_TRIGGER_SCAN:
> -		wpa_printf(MSG_DEBUG, "nl80211: Scan trigger");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Scan trigger");
>  		break;
>  	case NL80211_CMD_NEW_SCAN_RESULTS:
> -		wpa_printf(MSG_DEBUG, "nl80211: New scan results available");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: New scan results available");
>  		drv->scan_complete_events = 1;
>  		eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv,
>  				     drv->ctx);
>  		send_scan_event(drv, 0, tb);
>  		break;
>  	case NL80211_CMD_SCAN_ABORTED:
> -		wpa_printf(MSG_DEBUG, "nl80211: Scan aborted");
> +		wpa_msg(drv->ctx, MSG_DEBUG, "nl80211: Scan aborted");
>  		/*
>  		 * Need to indicate that scan results are available in order
>  		 * not to make wpa_supplicant stop its scanning.
> @@ -4009,8 +4009,9 @@ static int wpa_driver_nl80211_set_ap(void *priv,
>  	if (!msg)
>  		return -ENOMEM;
>  
> -	wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
> -		   beacon_set);
> +	wpa_msg(drv->ctx, MSG_DEBUG,
> +		"nl80211: Set beacon (beacon_set=%d)",
> +		beacon_set);
>  	if (beacon_set)
>  		cmd = NL80211_CMD_SET_BEACON;
>  
> @@ -4117,8 +4118,9 @@ static int wpa_driver_nl80211_set_ap(void *priv,
>  
>  	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
>  	if (ret) {
> -		wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
> -			   ret, strerror(-ret));
> +		wpa_msg(drv->ctx, MSG_DEBUG,
> +			"nl80211: Beacon set failed: %d (%s)",
> +			ret, strerror(-ret));
>  	} else {
>  		bss->beacon_set = 1;
>  	}





More information about the Hostap mailing list