wireless/wapi: Remove logic that depnds on Linux netlink. Add (untested) build support.
This commit is contained in:
parent
eeb143415a
commit
806d2c731a
@ -555,27 +555,6 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
|
||||
int wapi_set_txpower(int sock, FAR const char *ifname, int power,
|
||||
wapi_txpower_flag_t flag);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_if_add
|
||||
*
|
||||
* Description:
|
||||
* Creates a virtual interface with name for interface ifname.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_if_add(int sock, FAR const char *ifname, FAR const char *name,
|
||||
wapi_mode_t mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_if_del
|
||||
*
|
||||
* Description:
|
||||
* Deletes a virtual interface with name.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_if_del(int sock, FAR const char *ifname);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_make_socket
|
||||
*
|
||||
|
44
wireless/wapi/Kconfig
Normal file
44
wireless/wapi/Kconfig
Normal file
@ -0,0 +1,44 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
menuconfig WIRELESS_WAPI
|
||||
bool "Temperature"
|
||||
default n
|
||||
depends on EXPERIMENTAL
|
||||
---help---
|
||||
Wapi is a tool by Volkan YAZICI <volkan.yazici@gmail.com> that can
|
||||
be used to manage 802.11 network.
|
||||
|
||||
if WIRELESS_WAPI
|
||||
|
||||
config WIRELESS_WAPI_CMDTOOL
|
||||
bool "Build command line tool"
|
||||
default n
|
||||
---help---
|
||||
By default, Wapi is build as only a library. If this option is
|
||||
selected than a simple command line tool that can be ran from NSH
|
||||
will also be generated.
|
||||
|
||||
config WIRELESS_WAPI_ENABLE_SET
|
||||
bool "Enable setting options"
|
||||
default n
|
||||
|
||||
config WIRELESS_WAPI_PROGNAME
|
||||
string "Program name"
|
||||
default "wapi"
|
||||
depends on BUILD_KERNEL
|
||||
---help---
|
||||
This is the name of the program that will be use when the NSH ELF
|
||||
program is installed.
|
||||
|
||||
config WIRELESS_WAPI_STACKSIZE
|
||||
int "Stack size (bytes)"
|
||||
default 2048
|
||||
|
||||
config WIRELESS_WAPI_PRIORITY
|
||||
int "Command priority"
|
||||
default 100
|
||||
|
||||
endif
|
40
wireless/wapi/Make.defs
Normal file
40
wireless/wapi/Make.defs
Normal file
@ -0,0 +1,40 @@
|
||||
############################################################################
|
||||
# apps/wireless/wapi/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_WIRELESS_WAPI),y)
|
||||
CONFIGURED_APPS += wireless/wapi
|
||||
endif
|
||||
|
149
wireless/wapi/Makefile
Normal file
149
wireless/wapi/Makefile
Normal file
@ -0,0 +1,149 @@
|
||||
############################################################################
|
||||
# apps/wireless/wapi/Makefile
|
||||
#
|
||||
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# TODO, this makefile should run make under the app dirs, instead of
|
||||
# sourcing the Make.defs!
|
||||
|
||||
-include $(TOPDIR)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# LM-75 Temperature Sensor Application
|
||||
|
||||
CONFIG_WIRELESS_WAPI_PRIORITY ?= 100
|
||||
CONFIG_WIRELESS_WAPI_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = temp
|
||||
PRIORITY = $(CONFIG_WIRELESS_WAPI_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_WIRELESS_WAPI_STACKSIZE)
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
MAINSRC =
|
||||
|
||||
include $(APPDIR)/wireless/wapi/src/Make.defs
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifneq ($(CONFIG_BUILD_KERNEL),y)
|
||||
OBJS += $(MAINOBJ)
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
BIN = ..\..\libapps$(LIBEXT)
|
||||
else
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = ..\\..\\libapps$(LIBEXT)
|
||||
else
|
||||
BIN = ../../libapps$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
|
||||
else
|
||||
INSTALL_DIR = $(BIN_DIR)
|
||||
endif
|
||||
|
||||
CONFIG_WAPI_PROGNAME ?= lm75$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_WAPI_PROGNAME)
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: context depend clean distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
$(call ARCHIVE, $(BIN), $(OBJS))
|
||||
$(Q) touch .built
|
||||
|
||||
ifeq ($(CONFIG_BUILD_KERNEL),y)
|
||||
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
|
||||
@echo "LD: $(PROGNAME)"
|
||||
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
|
||||
$(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
|
||||
|
||||
install: $(BIN_DIR)$(DELIM)$(PROGNAME)
|
||||
|
||||
else
|
||||
install:
|
||||
|
||||
endif
|
||||
|
||||
# Register application
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),lm75_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
context:
|
||||
endif
|
||||
|
||||
# Create dependencies
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
$(call DELFILE, .built)
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
||||
.PHONY: preconfig
|
||||
preconfig:
|
@ -1,118 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/examples/ifadd.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "include/wireless/wapi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static int parse_wapi_mode(FAR const char *s, FAR wapi_mode_t * mode)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (!strcmp(s, "auto"))
|
||||
{
|
||||
*mode = WAPI_MODE_AUTO;
|
||||
else if (!strcmp(s, "adhoc"))
|
||||
{
|
||||
*mode = WAPI_MODE_ADHOC;
|
||||
}
|
||||
else if (!strcmp(s, "managed"))
|
||||
{
|
||||
*mode = WAPI_MODE_MANAGED;
|
||||
}
|
||||
else if (!strcmp(s, "master"))
|
||||
{
|
||||
*mode = WAPI_MODE_MASTER;
|
||||
}
|
||||
else if (!strcmp(s, "repeat"))
|
||||
{
|
||||
*mode = WAPI_MODE_REPEAT;
|
||||
}
|
||||
else if (!strcmp(s, "second"))
|
||||
{
|
||||
*mode = WAPI_MODE_SECOND;
|
||||
}
|
||||
else if (!strcmp(s, "monitor"))
|
||||
{
|
||||
*mode = WAPI_MODE_MONITOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int ifadd_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
wapi_mode_t mode;
|
||||
FAR const char *ifname;
|
||||
FAR const char *name;
|
||||
int ret;
|
||||
|
||||
if (argc != 4)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <IFNAME> <NAME> <MODE>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ifname = argv[1];
|
||||
name = argv[2];
|
||||
|
||||
if (parse_wapi_mode(argv[3], &mode))
|
||||
{
|
||||
fprintf(stderr, "Unknown mode: %s!\n", argv[3]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ret = wapi_if_add(-1, ifname, name, mode);
|
||||
fprintf(stderr, "wapi_if_add(): ret: %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/examples/ifdel.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "include/wireless/wapi.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int ifdel_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <IFNAME>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ret = wapi_if_del(-1, argv[1]);
|
||||
fprintf(stderr, "wapi_if_del(): ret: %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/examples/sample.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "sample.c"
|
@ -1,36 +0,0 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/examples/sample.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#define ENABLE_SET
|
||||
#include "sample.c"
|
49
wireless/wapi/src/Make.defs
Normal file
49
wireless/wapi/src/Make.defs
Normal file
@ -0,0 +1,49 @@
|
||||
############################################################################
|
||||
# apps/wireless/src/Make.defs
|
||||
#
|
||||
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_WIRELESS_WAPI),y)
|
||||
|
||||
CSRCS = network.c util.c wireless.c
|
||||
|
||||
ifeq ($(CONFIG_WIRELESS_WAPI_CMDTOOL),y)
|
||||
MAINSRC = wapi.c
|
||||
endif
|
||||
|
||||
DEPPATH += --dep-path src
|
||||
VPATH += :src
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(APPDIR)/wirelss/wapi/src}
|
||||
|
||||
endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/examples/sample.c
|
||||
* apps/wireless/wapi/src/wapi.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
@ -73,8 +73,8 @@ static void conf(int sock, FAR const char *ifname)
|
||||
{
|
||||
printf(", ip: %s", inet_ntoa(addr));
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
/* set ip (Make sure sin.sin_family is set to AF_INET.) */
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set ip (Make sure sin.sin_family is set to AF_INET.) */
|
||||
|
||||
ret = wapi_set_ip(sock, ifname, &addr);
|
||||
printf("\nwapi_set_ip(): ret: %d", ret);
|
||||
@ -92,7 +92,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
{
|
||||
printf(", netmask: %s", inet_ntoa(addr));
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* set netmask (Make sure sin.sin_family is set to AF_INET.) */
|
||||
|
||||
ret = wapi_set_netmask(sock, ifname, &addr);
|
||||
@ -127,7 +127,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
printf(", freq: %g", tmpfreq);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set freq */
|
||||
|
||||
ret = wapi_set_freq(sock, ifname, freq, freq_flag);
|
||||
@ -146,7 +146,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
printf(", essid: %s, essid_flag: %s",
|
||||
essid, g_wapi_essid_flags[essid_flag]);
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set essid */
|
||||
|
||||
ret = wapi_set_essid(sock, ifname, essid, essid_flag);
|
||||
@ -164,7 +164,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
{
|
||||
printf(", mode: %s", g_wapi_modes[mode]);
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set operating mode */
|
||||
|
||||
ret = wapi_set_mode(sock, ifname, mode);
|
||||
@ -185,7 +185,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
ap.ether_addr_octet[2], ap.ether_addr_octet[3],
|
||||
ap.ether_addr_octet[4], ap.ether_addr_octet[5]);
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set ap */
|
||||
|
||||
ret = wapi_set_ap(sock, ifname, &ap);
|
||||
@ -204,7 +204,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
printf(", bitrate: %d, bitrate_flag: %s", bitrate,
|
||||
g_wapi_bitrate_flags[bitrate_flag]);
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set bitrate */
|
||||
|
||||
ret = wapi_set_bitrate(sock, ifname, bitrate, bitrate_flag);
|
||||
@ -223,7 +223,7 @@ static void conf(int sock, FAR const char *ifname)
|
||||
printf(", txpower: %d, txpower_flag: %s",
|
||||
txpower, g_wapi_txpower_flags[txpower_flag]);
|
||||
|
||||
#ifdef ENABLE_SET
|
||||
#ifdef CONFIG_WIRELESS_WAPI_ENABLE_SET
|
||||
/* Set txpower */
|
||||
|
||||
ret = wapi_set_txpower(sock, ifname, txpower, txpower_flag);
|
@ -36,14 +36,7 @@
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <linux/nl80211.h>
|
||||
#include <netlink/genl/genl.h>
|
||||
#include <netlink/genl/family.h>
|
||||
#include <netlink/genl/ctrl.h>
|
||||
#include <netlink/msg.h>
|
||||
#include <netlink/attr.h>
|
||||
|
||||
#include <iwlib.h>
|
||||
#include <nuttx/wireless/wireless.h>
|
||||
|
||||
#include "include/wireless/wapi.h"
|
||||
#include "util.h"
|
||||
@ -119,35 +112,6 @@ FAR const char *g_wapi_txpower_flags[] =
|
||||
"WAPI_TXPOWER_RELATIVE"
|
||||
};
|
||||
|
||||
/* Add/Delete */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WAPI_NL80211_CMD_IFADD,
|
||||
WAPI_NL80211_CMD_IFDEL
|
||||
} wapi_nl80211_cmd_t;
|
||||
|
||||
typedef struct wapi_nl80211_ifadd_ctx_t
|
||||
{
|
||||
FAR const char *name;
|
||||
wapi_mode_t mode;
|
||||
} wapi_nl80211_ifadd_ctx_t;
|
||||
|
||||
typedef struct wapi_nl80211_ifdel_ctx_t
|
||||
{
|
||||
} wapi_nl80211_ifdel_ctx_t;
|
||||
|
||||
typedef struct wapi_nl80211_ctx_t
|
||||
{
|
||||
FAR const char *ifname;
|
||||
wapi_nl80211_cmd_t cmd;
|
||||
union
|
||||
{
|
||||
wapi_nl80211_ifadd_ctx_t ifadd;
|
||||
wapi_nl80211_ifdel_ctx_t ifdel;
|
||||
} u;
|
||||
} wapi_nl80211_ctx_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@ -351,278 +315,6 @@ static int wapi_scan_event(FAR struct iw_event *event, FAR wapi_list_t *list)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nl_socket_alloc
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef LIBNL1
|
||||
static FAR struct nl_handle *nl_socket_alloc(void)
|
||||
{
|
||||
return nl_handle_alloc();
|
||||
}
|
||||
#endif /* LIBNL1 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nl_socket_free
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef LIBNL1
|
||||
static void nl_socket_free(FAR struct nl_sock *h)
|
||||
{
|
||||
nl_handle_destroy(h);
|
||||
}
|
||||
#endif /* LIBNL1 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_mode_to_iftype
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int wapi_mode_to_iftype(wapi_mode_t mode, FAR enum nl80211_iftype *type)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case WAPI_MODE_AUTO:
|
||||
*type = NL80211_IFTYPE_UNSPECIFIED;
|
||||
break;
|
||||
|
||||
case WAPI_MODE_ADHOC:
|
||||
*type = NL80211_IFTYPE_ADHOC;
|
||||
break;
|
||||
|
||||
case WAPI_MODE_MANAGED:
|
||||
*type = NL80211_IFTYPE_STATION;
|
||||
break;
|
||||
|
||||
case WAPI_MODE_MASTER:
|
||||
*type = NL80211_IFTYPE_AP;
|
||||
break;
|
||||
|
||||
case WAPI_MODE_MONITOR:
|
||||
*type = NL80211_IFTYPE_MONITOR;
|
||||
break;
|
||||
|
||||
default:
|
||||
WAPI_ERROR("No supported nl80211 iftype for mode: %s!\n",
|
||||
g_wapi_modes[mode]);
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nl80211_err_handler
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int nl80211_err_handler(FAR struct sockaddr_nl *nla,
|
||||
FAR struct nlmsgerr *err, FAR void *arg)
|
||||
{
|
||||
int *ret = arg;
|
||||
*ret = err->error;
|
||||
return NL_STOP;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nl80211_fin_handler
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int nl80211_fin_handler(FAR struct nl_msg *msg, FAR void *arg)
|
||||
{
|
||||
int *ret = arg;
|
||||
*ret = 0;
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nl80211_ack_handler
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int nl80211_ack_handler(FAR struct nl_msg *msg, FAR void *arg)
|
||||
{
|
||||
int *ret = arg;
|
||||
*ret = 0;
|
||||
return NL_STOP;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nl80211_cmd_handler
|
||||
*
|
||||
* Description:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int nl80211_cmd_handler(FAR const wapi_nl80211_ctx_t *ctx)
|
||||
{
|
||||
FAR struct nl_sock *sock;
|
||||
FAR struct nl_msg *msg;
|
||||
FAR struct nl_cb *cb;
|
||||
int family;
|
||||
int ifidx;
|
||||
int ret;
|
||||
|
||||
/* Allocate netlink socket. */
|
||||
|
||||
sock = nl_socket_alloc();
|
||||
if (!sock)
|
||||
{
|
||||
WAPI_ERROR("Failed to allocate netlink socket!\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Reset "msg" and "cb". */
|
||||
|
||||
msg = NULL;
|
||||
cb = NULL;
|
||||
|
||||
/* Connect to generic netlink socket on kernel side. */
|
||||
|
||||
if (genl_connect(sock))
|
||||
{
|
||||
WAPI_ERROR("Failed to connect to generic netlink!\n");
|
||||
ret = -ENOLINK;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Ask kernel to resolve family name to family id. */
|
||||
|
||||
ret = family = genl_ctrl_resolve(sock, "nl80211");
|
||||
if (ret < 0)
|
||||
{
|
||||
WAPI_ERROR("genl_ctrl_resolve() failed!\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Map given network interface name (ifname) to its corresponding index. */
|
||||
|
||||
ifidx = if_nametoindex(ctx->ifname);
|
||||
if (!ifidx)
|
||||
{
|
||||
WAPI_STRERROR("if_nametoindex(\"%s\")", ctx->ifname);
|
||||
ret = -errno;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Construct a generic netlink by allocating a new message. */
|
||||
|
||||
msg = nlmsg_alloc();
|
||||
if (!msg)
|
||||
{
|
||||
WAPI_ERROR("nlmsg_alloc() failed!\n");
|
||||
ret = -ENOMEM;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Append the requested command to the message. */
|
||||
|
||||
switch (ctx->cmd)
|
||||
{
|
||||
case WAPI_NL80211_CMD_IFADD:
|
||||
{
|
||||
enum nl80211_iftype iftype;
|
||||
|
||||
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0,
|
||||
NL80211_CMD_NEW_INTERFACE, 0);
|
||||
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
|
||||
|
||||
/* Get NL80211_IFTYPE_* for the given WAPI mode. */
|
||||
|
||||
ret = wapi_mode_to_iftype(ctx->u.ifadd.mode, &iftype);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto exit;
|
||||
}
|
||||
|
||||
NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ctx->u.ifadd.name);
|
||||
NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
|
||||
break;
|
||||
}
|
||||
|
||||
case WAPI_NL80211_CMD_IFDEL:
|
||||
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, 0,
|
||||
NL80211_CMD_DEL_INTERFACE, 0);
|
||||
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Finalize (send) the message. */
|
||||
|
||||
ret = nl_send_auto_complete(sock, msg);
|
||||
if (ret < 0)
|
||||
{
|
||||
WAPI_ERROR("nl_send_auto_complete() failed!\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Allocate a new callback handle. */
|
||||
|
||||
cb = nl_cb_alloc(NL_CB_VERBOSE);
|
||||
if (!cb)
|
||||
{
|
||||
WAPI_ERROR("nl_cb_alloc() failed\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Configure callback handlers. */
|
||||
|
||||
nl_cb_err(cb, NL_CB_CUSTOM, nl80211_err_handler, &ret);
|
||||
nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, nl80211_fin_handler, &ret);
|
||||
nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, nl80211_ack_handler, &ret);
|
||||
|
||||
/* Consume netlink replies. */
|
||||
|
||||
for (ret = 1; ret > 0;)
|
||||
{
|
||||
nl_recvmsgs(sock, cb);
|
||||
}
|
||||
|
||||
if (ret)
|
||||
{
|
||||
WAPI_ERROR("nl_recvmsgs() failed!\n");
|
||||
}
|
||||
|
||||
exit:
|
||||
/* Release resources and exit with "ret". */
|
||||
|
||||
nl_socket_free(sock);
|
||||
if (msg)
|
||||
{
|
||||
nlmsg_free(msg);
|
||||
}
|
||||
|
||||
if (cb)
|
||||
{
|
||||
free(cb);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
nla_put_failure:
|
||||
WAPI_ERROR("nla_put_failure!\n");
|
||||
ret = -1;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -1457,42 +1149,3 @@ alloc:
|
||||
free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_if_add
|
||||
*
|
||||
* Description:
|
||||
* Creates a virtual interface with name for interface ifname.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_if_add(int sock, FAR const char *ifname, FAR const char *name,
|
||||
wapi_mode_t mode)
|
||||
{
|
||||
wapi_nl80211_ctx_t ctx;
|
||||
|
||||
ctx.ifname = ifname;
|
||||
ctx.cmd = WAPI_NL80211_CMD_IFADD;
|
||||
ctx.u.ifadd.name = name;
|
||||
ctx.u.ifadd.mode = mode;
|
||||
|
||||
return nl80211_cmd_handler(&ctx);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_if_del
|
||||
*
|
||||
* Description:
|
||||
* Deletes a virtual interface with name.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_if_del(int sock, FAR const char *ifname)
|
||||
{
|
||||
wapi_nl80211_ctx_t ctx;
|
||||
|
||||
ctx.ifname = ifname;
|
||||
ctx.cmd = WAPI_NL80211_CMD_IFDEL;
|
||||
|
||||
return nl80211_cmd_handler(&ctx);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user