~ubuntu-branches/ubuntu/trusty/wpa/trusty

« back to all changes in this revision

Viewing changes to src/wps/ndef.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-03-04 16:13:24 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140304161324-md40gw8imcectbuu
Tags: 2.1-0ubuntu1
* New upstream release (LP: #1099755)
* debian/get-orig-source: update for new git repository for the current
  hostap/wpasupplicant versions.
* Dropped patches due to being applied upstream and included in the current
  source tarball:
  - debian/patches/11_wpa_gui_ftbfs_gcc_4_7.patch
  - debian/patches/13_human_readable_signal.patch
  - debian/patches/git_deinit_p2p_context_on_mgmt_remove_ff1f9c8.patch
  - debian/patches/libnl3-includes.patch
* debian/patches/git_accept_client_cert_from_server.patch: revert the commit:
  "OpenSSL: Do not accept SSL Client certificate for server", which breaks
  many AAA servers that include both client and server EKUs. Cherry-picked
  from hostap git commit b62d5b5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * NDEF(NFC Data Exchange Format) routines for Wi-Fi Protected Setup
3
3
 *   Reference is "NFCForum-TS-NDEF_1.0 2006-07-24".
4
 
 * Copyright (c) 2009, Masashi Honma <honma@ictec.co.jp>
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License version 2 as
8
 
 * published by the Free Software Foundation.
9
 
 *
10
 
 * Alternatively, this software may be distributed under the terms of BSD
11
 
 * license.
12
 
 *
13
 
 * See README and COPYING for more details.
 
4
 * Copyright (c) 2009-2012, Masashi Honma <masashi.honma@gmail.com>
 
5
 *
 
6
 * This software may be distributed under the terms of the BSD license.
 
7
 * See README for more details.
14
8
 */
15
9
 
16
10
#include "includes.h"
17
11
#include "common.h"
18
12
#include "wps/wps.h"
19
 
#include "wps/wps_i.h"
20
13
 
21
14
#define FLAG_MESSAGE_BEGIN (1 << 7)
22
15
#define FLAG_MESSAGE_END (1 << 6)
23
16
#define FLAG_CHUNK (1 << 5)
24
17
#define FLAG_SHORT_RECORD (1 << 4)
25
18
#define FLAG_ID_LENGTH_PRESENT (1 << 3)
 
19
#define FLAG_TNF_NFC_FORUM (0x01)
26
20
#define FLAG_TNF_RFC2046 (0x02)
27
21
 
28
22
struct ndef_record {
29
 
        u8 *type;
30
 
        u8 *id;
31
 
        u8 *payload;
 
23
        const u8 *type;
 
24
        const u8 *id;
 
25
        const u8 *payload;
32
26
        u8 type_length;
33
27
        u8 id_length;
34
28
        u32 payload_length;
36
30
};
37
31
 
38
32
static char wifi_handover_type[] = "application/vnd.wfa.wsc";
 
33
static char p2p_handover_type[] = "application/vnd.wfa.p2p";
39
34
 
40
 
static int ndef_parse_record(u8 *data, u32 size, struct ndef_record *record)
 
35
static int ndef_parse_record(const u8 *data, u32 size,
 
36
                             struct ndef_record *record)
41
37
{
42
 
        u8 *pos = data + 1;
 
38
        const u8 *pos = data + 1;
43
39
 
44
40
        if (size < 2)
45
41
                return -1;
78
74
}
79
75
 
80
76
 
81
 
static struct wpabuf * ndef_parse_records(struct wpabuf *buf,
 
77
static struct wpabuf * ndef_parse_records(const struct wpabuf *buf,
82
78
                                          int (*filter)(struct ndef_record *))
83
79
{
84
80
        struct ndef_record record;
85
81
        int len = wpabuf_len(buf);
86
 
        u8 *data = wpabuf_mhead(buf);
 
82
        const u8 *data = wpabuf_head(buf);
87
83
 
88
84
        while (len > 0) {
89
85
                if (ndef_parse_record(data, len, &record) < 0) {
103
99
 
104
100
static struct wpabuf * ndef_build_record(u8 flags, void *type,
105
101
                                         u8 type_length, void *id,
106
 
                                         u8 id_length, void *payload,
107
 
                                         u32 payload_length)
 
102
                                         u8 id_length,
 
103
                                         const struct wpabuf *payload)
108
104
{
109
105
        struct wpabuf *record;
110
106
        size_t total_len;
111
107
        int short_record;
112
108
        u8 local_flag;
 
109
        size_t payload_length = wpabuf_len(payload);
113
110
 
114
111
        short_record = payload_length < 256 ? 1 : 0;
115
112
 
144
141
                wpabuf_put_u8(record, id_length);
145
142
        wpabuf_put_data(record, type, type_length);
146
143
        wpabuf_put_data(record, id, id_length);
147
 
        wpabuf_put_data(record, payload, payload_length);
 
144
        wpabuf_put_buf(record, payload);
148
145
        return record;
149
146
}
150
147
 
160
157
}
161
158
 
162
159
 
163
 
struct wpabuf * ndef_parse_wifi(struct wpabuf *buf)
 
160
struct wpabuf * ndef_parse_wifi(const struct wpabuf *buf)
164
161
{
165
162
        return ndef_parse_records(buf, wifi_filter);
166
163
}
167
164
 
168
165
 
169
 
struct wpabuf * ndef_build_wifi(struct wpabuf *buf)
 
166
struct wpabuf * ndef_build_wifi(const struct wpabuf *buf)
170
167
{
171
168
        return ndef_build_record(FLAG_MESSAGE_BEGIN | FLAG_MESSAGE_END |
172
169
                                 FLAG_TNF_RFC2046, wifi_handover_type,
173
 
                                 os_strlen(wifi_handover_type), NULL, 0,
174
 
                                 wpabuf_mhead(buf), wpabuf_len(buf));
 
170
                                 os_strlen(wifi_handover_type), NULL, 0, buf);
 
171
}
 
172
 
 
173
 
 
174
static int p2p_filter(struct ndef_record *record)
 
175
{
 
176
        if (record->type_length != os_strlen(p2p_handover_type))
 
177
                return 0;
 
178
        if (os_memcmp(record->type, p2p_handover_type,
 
179
                      os_strlen(p2p_handover_type)) != 0)
 
180
                return 0;
 
181
        return 1;
 
182
}
 
183
 
 
184
 
 
185
struct wpabuf * ndef_parse_p2p(const struct wpabuf *buf)
 
186
{
 
187
        return ndef_parse_records(buf, p2p_filter);
 
188
}
 
189
 
 
190
 
 
191
struct wpabuf * ndef_build_p2p(const struct wpabuf *buf)
 
192
{
 
193
        return ndef_build_record(FLAG_MESSAGE_BEGIN | FLAG_MESSAGE_END |
 
194
                                 FLAG_TNF_RFC2046, p2p_handover_type,
 
195
                                 os_strlen(p2p_handover_type), NULL, 0, buf);
175
196
}