P2P: Provide mechanism for figuring out p2p_scan_ie() buffer need

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.
This commit is contained in:
Jouni Malinen 2011-04-28 16:14:35 +03:00 committed by Jouni Malinen
parent fc6997b345
commit 206e1f422f
5 changed files with 24 additions and 4 deletions

View 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;

View 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);

View 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()

View 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);

View 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);