From 65c8a29370e46523464f05ec5d594ba12631b6d4 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Wed, 15 Jul 2015 12:52:23 -0500 Subject: [PATCH] wsc: Add WSC attribute iterator --- Makefile.am | 2 +- src/wsc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/wsc.h | 29 +++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/wsc.c diff --git a/Makefile.am b/Makefile.am index 3f02befc..b11d0a79 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,7 +59,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \ src/agent.h src/agent.c \ src/storage.h src/storage.c \ src/network.h src/network.c \ - src/wsc.h \ + src/wsc.h src/wsc.c \ iwd.h src_iwd_LDADD = ell/libell-internal.la diff --git a/src/wsc.c b/src/wsc.c new file mode 100644 index 00000000..9bcd7558 --- /dev/null +++ b/src/wsc.c @@ -0,0 +1,68 @@ +/* + * + * Wireless daemon for Linux + * + * Copyright (C) 2015 Intel Corporation. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include + +#include "wsc.h" + +void wsc_attr_iter_init(struct wsc_attr_iter *iter, const unsigned char *pdu, + unsigned int len) +{ + iter->pdu = pdu; + iter->max = len; + iter->pos = 0; +} + +bool wsc_attr_iter_next(struct wsc_attr_iter *iter) +{ + const unsigned char *start = iter->pdu + iter->pos; + const unsigned char *end = iter->pdu + iter->max; + unsigned short type; + unsigned short len; + + /* Make sure we have at least type + len fields */ + if (iter->pos + 4 >= iter->max) + return false; + + type = l_get_be16(start); + start += 2; + + len = l_get_be16(start); + start += 2; + + if (start + len > end) + return false; + + iter->type = type; + iter->len = len; + iter->data = start; + + iter->pos = start + len - iter->pdu; + + return true; +} diff --git a/src/wsc.h b/src/wsc.h index 40f9cca1..ddc170ea 100644 --- a/src/wsc.h +++ b/src/wsc.h @@ -256,3 +256,32 @@ enum wsc_config_state { WSC_CONFIG_STATE_NOT_CONFIGURED = 0x01, WSC_CONFIG_STATE_CONFIGURED = 0x02, }; + +struct wsc_attr_iter { + unsigned int max; + unsigned int pos; + const unsigned char *pdu; + unsigned short type; + unsigned short len; + const unsigned char *data; +}; + +void wsc_attr_iter_init(struct wsc_attr_iter *iter, const unsigned char *pdu, + unsigned int len); +bool wsc_attr_iter_next(struct wsc_attr_iter *iter); + +static inline unsigned int wsc_attr_iter_get_type(struct wsc_attr_iter *iter) +{ + return iter->type; +} + +static inline unsigned int wsc_attr_iter_get_length(struct wsc_attr_iter *iter) +{ + return iter->len; +} + +static inline const unsigned char *wsc_attr_iter_get_data( + struct wsc_attr_iter *iter) +{ + return iter->data; +}