p2p on 32-bit architectures

Jouni Malinen j at w1.fi
Fri May 27 11:23:30 EDT 2011


On Thu, May 26, 2011 at 04:07:05PM -0700, Sam Leffler wrote:
> Building w/ P2P support enabled for a 32-bit target yields these complaints:
> 
> p2p_supplicant.c: In function 'wpas_p2p_sd_request':
> p2p_supplicant.c:1672: warning: cast to pointer from integer of different size
> p2p_supplicant.c: In function 'wpas_p2p_sd_cancel_request':
> p2p_supplicant.c:1702: warning: cast from pointer to integer of different size

Yes... I've been too lazy to fix these two. Some of the other similar
cases were cleaned up with better typecasts, but the cases on
driver-based P2P management still remain.

> The first issue is wpa_drv_p2p_sd_request's return value is being cast
> to void * but the return value is u64 in driver_i.h:
> 
> static inline u64 wpa_drv_p2p_sd_request(struct wpa_supplicant *wpa_s,
>                                          const u8 *dst,
>                                          const struct wpabuf *tlvs)
> 
> This does not work unless we're ok blindly lopping off 32 bits.

Well, this is only used if WPA_DRIVER_FLAGS_P2P_MGMT is set and the
driver wrapper implement p2p_sd_request. No such driver wrapper exists
in hostap.git.

> The second complaint is the u64 cast:
> 
> nt wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, void *req)
> {
>         if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
>                 return wpa_drv_p2p_sd_cancel_request(wpa_s, (u64) req);

Similarly, this code path is not really used in hostap.git.

> This needs to use uintptr_t or similar to be portable.

Unfortunately, that is not really portable solution since what would be
needed here is a maximum of sizeof(void*) and sizeof(u64). uintptr_t may
not meet the second part of this and it could result in potential issues
should a new driver wrapper show up with driver-based P2P service
discovery implementation and that kernel code using 64-bit cookies to
identify the requests.

> This makes me believe no-one's tried this on a 32-bit arch?

That particular code path has received quite limited testing because it
is not really used at all with most drivers. I'm aware of one driver
wrapper that is not yet in hostap.git that could potentially use this
path. I think that it would be fine in case of 32-bit kernel, but there
could be potential issues with 64-bit kernel and 32-bit user space.

Something like the following patch could be used to silence the
warnings, but even that has some potential issues: it would not
necessarily work on 128-bit CPUs in some driver combinations..


diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 8604d16..3869ac5 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -2302,7 +2302,7 @@ static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
 	if (sscanf(cmd, "%llx", &val) != 1)
 		return -1;
 	req = val;
-	return wpas_p2p_sd_cancel_request(wpa_s, (void *) (unsigned long) req);
+	return wpas_p2p_sd_cancel_request(wpa_s, req);
 }
 
 
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 03d1672..94a548f 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -1665,26 +1665,26 @@ void wpas_sd_response(void *ctx, const u8 *sa, u16 update_indic,
 }
 
 
-void * wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
-			   const struct wpabuf *tlvs)
+u64 wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
+			const struct wpabuf *tlvs)
 {
 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
-		return (void *) wpa_drv_p2p_sd_request(wpa_s, dst, tlvs);
+		return wpa_drv_p2p_sd_request(wpa_s, dst, tlvs);
 	if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
-		return NULL;
-	return p2p_sd_request(wpa_s->global->p2p, dst, tlvs);
+		return 0;
+	return (unsigned long) p2p_sd_request(wpa_s->global->p2p, dst, tlvs);
 }
 
 
-void * wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
-				u8 version, const char *query)
+u64 wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
+			     u8 version, const char *query)
 {
 	struct wpabuf *tlvs;
-	void *ret;
+	u64 ret;
 
 	tlvs = wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query));
 	if (tlvs == NULL)
-		return NULL;
+		return 0;
 	wpabuf_put_le16(tlvs, 1 + 1 + 1 + os_strlen(query));
 	wpabuf_put_u8(tlvs, P2P_SERV_UPNP); /* Service Protocol Type */
 	wpabuf_put_u8(tlvs, 1); /* Service Transaction ID */
@@ -1696,13 +1696,14 @@ void * wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
 }
 
 
-int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, void *req)
+int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, u64 req)
 {
 	if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
-		return wpa_drv_p2p_sd_cancel_request(wpa_s, (u64) req);
+		return wpa_drv_p2p_sd_cancel_request(wpa_s, req);
 	if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
 		return -1;
-	return p2p_sd_cancel_request(wpa_s->global->p2p, req);
+	return p2p_sd_cancel_request(wpa_s->global->p2p,
+				     (void *) (unsigned long) req);
 }
 
 
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 69df475..d32bd8f 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -78,11 +78,11 @@ void wpas_sd_request(void *ctx, int freq, const u8 *sa, u8 dialog_token,
 		     u16 update_indic, const u8 *tlvs, size_t tlvs_len);
 void wpas_sd_response(void *ctx, const u8 *sa, u16 update_indic,
 		      const u8 *tlvs, size_t tlvs_len);
-void * wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
-			   const struct wpabuf *tlvs);
-void * wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
-				u8 version, const char *query);
-int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, void *req);
+u64 wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
+			const struct wpabuf *tlvs);
+u64 wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
+			     u8 version, const char *query);
+int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, u64 req);
 void wpas_p2p_sd_response(struct wpa_supplicant *wpa_s, int freq,
 			  const u8 *dst, u8 dialog_token,
 			  const struct wpabuf *resp_tlvs);

-- 
Jouni Malinen                                            PGP id EFC895FA


More information about the HostAP mailing list