From 523d7645c4ac02f79c793b536f93f58bd5452a4f Mon Sep 17 00:00:00 2001 From: Simon Piriou Date: Sun, 21 May 2017 16:24:49 +0200 Subject: [PATCH] wapi: add basic wapi_event_stream_extract implementation --- nshlib/Makefile | 2 ++ wireless/wapi/src/wireless.c | 59 ++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/nshlib/Makefile b/nshlib/Makefile index 6490d74ee..47ea7ab9f 100644 --- a/nshlib/Makefile +++ b/nshlib/Makefile @@ -75,8 +75,10 @@ endif ifeq ($(CONFIG_NET),y) CSRCS += nsh_netinit.c nsh_netcmds.c ifeq ($(CONFIG_WIRELESS_WAPI),y) +ifeq ($(CONFIG_NSH_NETINIT),y) CSRCS += nsh_associate.c endif +endif ifeq ($(CONFIG_NET_ROUTE),y) CSRCS += nsh_routecmds.c endif diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c index f76cd250b..c45dea472 100644 --- a/wireless/wapi/src/wireless.c +++ b/wireless/wapi/src/wireless.c @@ -224,7 +224,57 @@ static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream, { #warning Missing logic // return iw_extract_event_stream((struct stream_descr *)stream, iwe, 0); -return -ENOSYS; + + int ret; + struct iw_event *iwe_stream; + + if (stream->current + offsetof(struct iw_event, u) > stream->end) + { + /* Nothing to process */ + + return 0; + } + + iwe_stream = (struct iw_event*)stream->current; + + if (stream->current + iwe_stream->len > stream->end || + iwe_stream->len < offsetof(struct iw_event, u)) + { + return -1; + } + + ret = 1; + + switch (iwe_stream->cmd) + { + case SIOCGIWESSID: + case IWEVGENIE: + iwe->cmd = iwe_stream->cmd; + iwe->len = offsetof(struct iw_event, u) + sizeof(struct iw_point); + iwe->u.data.flags = iwe_stream->u.data.flags; + iwe->u.data.length = iwe_stream->u.data.length; + + iwe->u.data.pointer = (FAR void*)(stream->current + + offsetof(struct iw_event, u) + + (unsigned long)iwe_stream->u.data.pointer); + break; + + default: + if (iwe_stream->len > sizeof(*iwe)) + { + WAPI_ERROR("Unhandled event size 0x%x %d\n", iwe_stream->cmd, + iwe_stream->len); + iwe->cmd = 0; + iwe->len = offsetof(struct iw_event, u); + break; + } + memcpy(iwe, iwe_stream, iwe_stream->len); + } + + /* Update stream to next event */ + + stream->current += iwe_stream->len; + return ret; } /**************************************************************************** @@ -1113,6 +1163,8 @@ alloc: return -errcode; } + printf("got %d bytes\n", wrq.u.data.length); + /* We have the results, process them. */ if (wrq.u.data.length) @@ -1125,7 +1177,8 @@ alloc: { /* Get the next event from the stream */ - if ((ret = wapi_event_stream_extract(&stream, &iwe)) >= 0) + ret = wapi_event_stream_extract(&stream, &iwe); + if (ret > 0) { int eventret = wapi_scan_event(&iwe, aps); if (eventret < 0) @@ -1133,7 +1186,7 @@ alloc: ret = eventret; } } - else + else if (ret < 0) { WAPI_ERROR("ERROR: wapi_event_stream_extract() failed!\n"); }