~ubuntu-branches/ubuntu/saucy/wpasupplicant/saucy

« back to all changes in this revision

Viewing changes to src/common/ieee802_11_common.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2010-11-22 09:43:43 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20101122094343-qgsxaojvmswfri77
Tags: 0.7.3-0ubuntu1
* Get wpasupplicant 0.7.3 from Debian's SVN. Leaving 0.7.3-1 as unreleased
  for now.
* Build-Depend on debhelper 8, since the packaging from Debian uses compat 8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * IEEE 802.11 Common routines
3
 
 * Copyright (c) 2002-2008, Jouni Malinen <j@w1.fi>
 
3
 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License version 2 as
19
19
#include "ieee802_11_common.h"
20
20
 
21
21
 
22
 
static int ieee802_11_parse_vendor_specific(u8 *pos, size_t elen,
 
22
static int ieee802_11_parse_vendor_specific(const u8 *pos, size_t elen,
23
23
                                            struct ieee802_11_elems *elems,
24
24
                                            int show_errors)
25
25
{
131
131
 * @show_errors: Whether to show parsing errors in debug log
132
132
 * Returns: Parsing result
133
133
 */
134
 
ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
 
134
ParseRes ieee802_11_parse_elems(const u8 *start, size_t len,
135
135
                                struct ieee802_11_elems *elems,
136
136
                                int show_errors)
137
137
{
138
138
        size_t left = len;
139
 
        u8 *pos = start;
 
139
        const u8 *pos = start;
140
140
        int unknown = 0;
141
141
 
142
142
        os_memset(elems, 0, sizeof(*elems));
257
257
 
258
258
        return unknown ? ParseUnknown : ParseOK;
259
259
}
 
260
 
 
261
 
 
262
int ieee802_11_ie_count(const u8 *ies, size_t ies_len)
 
263
{
 
264
        int count = 0;
 
265
        const u8 *pos, *end;
 
266
 
 
267
        if (ies == NULL)
 
268
                return 0;
 
269
 
 
270
        pos = ies;
 
271
        end = ies + ies_len;
 
272
 
 
273
        while (pos + 2 <= end) {
 
274
                if (pos + 2 + pos[1] > end)
 
275
                        break;
 
276
                count++;
 
277
                pos += 2 + pos[1];
 
278
        }
 
279
 
 
280
        return count;
 
281
}
 
282
 
 
283
 
 
284
struct wpabuf * ieee802_11_vendor_ie_concat(const u8 *ies, size_t ies_len,
 
285
                                            u32 oui_type)
 
286
{
 
287
        struct wpabuf *buf;
 
288
        const u8 *end, *pos, *ie;
 
289
 
 
290
        pos = ies;
 
291
        end = ies + ies_len;
 
292
        ie = NULL;
 
293
 
 
294
        while (pos + 1 < end) {
 
295
                if (pos + 2 + pos[1] > end)
 
296
                        return NULL;
 
297
                if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
 
298
                    WPA_GET_BE32(&pos[2]) == oui_type) {
 
299
                        ie = pos;
 
300
                        break;
 
301
                }
 
302
                pos += 2 + pos[1];
 
303
        }
 
304
 
 
305
        if (ie == NULL)
 
306
                return NULL; /* No specified vendor IE found */
 
307
 
 
308
        buf = wpabuf_alloc(ies_len);
 
309
        if (buf == NULL)
 
310
                return NULL;
 
311
 
 
312
        /*
 
313
         * There may be multiple vendor IEs in the message, so need to
 
314
         * concatenate their data fields.
 
315
         */
 
316
        while (pos + 1 < end) {
 
317
                if (pos + 2 + pos[1] > end)
 
318
                        break;
 
319
                if (pos[0] == WLAN_EID_VENDOR_SPECIFIC && pos[1] >= 4 &&
 
320
                    WPA_GET_BE32(&pos[2]) == oui_type)
 
321
                        wpabuf_put_data(buf, pos + 6, pos[1] - 4);
 
322
                pos += 2 + pos[1];
 
323
        }
 
324
 
 
325
        return buf;
 
326
}