]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Provide mechanism for figuring out p2p_scan_ie() buffer need
authorJouni Malinen <jouni.malinen@atheros.com>
Thu, 28 Apr 2011 13:14:35 +0000 (16:14 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 29 Sep 2011 19:18:23 +0000 (22:18 +0300)
The new function, p2p_scan_ie_buf_len(), can be used to figure out
how large a buffer needs to be allocated for p2p_scan_ie() use. This
makes it easier to add new data into the buffer without forcing all
callers to be updated to use a larger buffer.

src/drivers/driver_test.c
src/p2p/p2p.c
src/p2p/p2p.h
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/scan.c

index cdae739e4db472968e0bd15b50a58dca5da8caf7..a34cc546911f947f637b7619d4b7ce630ed0ad7c 100644 (file)
@@ -2983,6 +2983,7 @@ static int test_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
        int ret;
        struct wpabuf *wps_ie, *ies;
        int social_channels[] = { 2412, 2437, 2462, 0, 0 };
+       size_t ielen;
 
        wpa_printf(MSG_DEBUG, "%s(type=%d freq=%d)",
                   __func__, type, freq);
@@ -3004,7 +3005,8 @@ static int test_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
        if (wps_ie == NULL)
                return -1;
 
-       ies = wpabuf_alloc(wpabuf_len(wps_ie) + 100);
+       ielen = p2p_scan_ie_buf_len(drv->p2p);
+       ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
        if (ies == NULL) {
                wpabuf_free(wps_ie);
                return -1;
index 816196af2f271d744b43d4d703ed916df3a28db0..3cb8f4dc7575cd4c9fcff24eec5dc576435bea9f 100644 (file)
@@ -2462,6 +2462,12 @@ void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies)
 }
 
 
+size_t p2p_scan_ie_buf_len(struct p2p_data *p2p)
+{
+       return 100;
+}
+
+
 int p2p_ie_text(struct wpabuf *p2p_ie, char *buf, char *end)
 {
        return p2p_attr_text(p2p_ie, buf, end);
index 4cab3da9a68b7df95b4009747cd6ac26174f98f8..31e83d5ff2c5981c37219daf941890dd676d0934 100644 (file)
@@ -1343,6 +1343,13 @@ int p2p_assoc_req_ie(struct p2p_data *p2p, const u8 *bssid, u8 *buf,
  */
 void p2p_scan_ie(struct p2p_data *p2p, struct wpabuf *ies);
 
+/**
+ * p2p_scan_ie_buf_len - Get maximum buffer length needed for p2p_scan_ie
+ * @p2p: P2P module context from p2p_init()
+ * Returns: Number of octets that p2p_scan_ie() may add to the buffer
+ */
+size_t p2p_scan_ie_buf_len(struct p2p_data *p2p);
+
 /**
  * p2p_go_params - Generate random P2P group parameters
  * @p2p: P2P module context from p2p_init()
index f1912f3e9614d3c66ea332ce63f7a373ea1fddd3..7d3bac181e6cd1f56416128b4c2d3cef50144416 100644 (file)
@@ -92,6 +92,7 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
        int ret;
        struct wpabuf *wps_ie, *ies;
        int social_channels[] = { 2412, 2437, 2462, 0, 0 };
+       size_t ielen;
 
        if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
                return -1;
@@ -110,7 +111,8 @@ static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
        if (wps_ie == NULL)
                return -1;
 
-       ies = wpabuf_alloc(wpabuf_len(wps_ie) + 100);
+       ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
+       ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
        if (ies == NULL) {
                wpabuf_free(wps_ie);
                return -1;
@@ -2766,6 +2768,7 @@ static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
        int ret;
        struct wpa_driver_scan_params params;
        struct wpabuf *wps_ie, *ies;
+       size_t ielen;
 
        os_memset(&params, 0, sizeof(params));
 
@@ -2782,7 +2785,8 @@ static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
                return;
        }
 
-       ies = wpabuf_alloc(wpabuf_len(wps_ie) + 100);
+       ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
+       ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
        if (ies == NULL) {
                wpabuf_free(wps_ie);
                wpas_p2p_scan_res_join(wpa_s, NULL);
index 5be661a2e82f0f2da0cbd68528db94ae21e3e047..9159d31b9e1546455776ebb0d137243270aac28d 100644 (file)
@@ -471,7 +471,8 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
 
 #ifdef CONFIG_P2P
        if (wps_ie) {
-               if (wpabuf_resize(&wps_ie, 100) == 0) {
+               size_t ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
+               if (wpabuf_resize(&wps_ie, ielen) == 0) {
                        wpas_p2p_scan_ie(wpa_s, wps_ie);
                        params.extra_ies = wpabuf_head(wps_ie);
                        params.extra_ies_len = wpabuf_len(wps_ie);