Merge remote-tracking branch 'origin/master' into ieee802154
This commit is contained in:
commit
77ae3bf02b
@ -1,8 +1,13 @@
|
||||
/****************************************************************************
|
||||
* apps/include/wireless/wapi.h
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
* Copyright (C) 2011, 2017Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Adapted for Nuttx from WAPI:
|
||||
*
|
||||
* 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:
|
||||
@ -48,14 +53,6 @@
|
||||
|
||||
#define WAPI_ESSID_MAX_SIZE IW_ESSID_MAX_SIZE
|
||||
|
||||
/* Path to /proc/net/wireless. (Requires procfs mounted.) */
|
||||
|
||||
#define WAPI_PROC_NET_WIRELESS "/proc/net/wireless"
|
||||
|
||||
/* Path to /proc/net/route. (Requires procfs mounted.) */
|
||||
|
||||
#define WAPI_PROC_NET_ROUTE "/proc/net/route"
|
||||
|
||||
/* Buffer size while reading lines from PROC_NET_ files. */
|
||||
|
||||
#define WAPI_PROC_LINE_SIZE 1024
|
||||
@ -96,13 +93,14 @@ typedef enum
|
||||
|
||||
typedef enum
|
||||
{
|
||||
WAPI_MODE_AUTO = IW_MODE_AUTO, /* Driver decides. */
|
||||
WAPI_MODE_ADHOC = IW_MODE_ADHOC, /* Single cell network. */
|
||||
WAPI_MODE_MANAGED = IW_MODE_INFRA, /* Multi cell network, roaming, ... */
|
||||
WAPI_MODE_MASTER = IW_MODE_MASTER, /* Synchronisation master or access point. */
|
||||
WAPI_MODE_REPEAT = IW_MODE_REPEAT, /* Wireless repeater, forwarder. */
|
||||
WAPI_MODE_SECOND = IW_MODE_SECOND, /* Secondary master/repeater, backup. */
|
||||
WAPI_MODE_MONITOR = IW_MODE_MONITOR /* Passive monitor, listen only. */
|
||||
WAPI_MODE_AUTO = IW_MODE_AUTO, /* Driver decides. */
|
||||
WAPI_MODE_ADHOC = IW_MODE_ADHOC, /* Single cell network. */
|
||||
WAPI_MODE_MANAGED = IW_MODE_INFRA, /* Multi cell network, roaming, ... */
|
||||
WAPI_MODE_MASTER = IW_MODE_MASTER, /* Synchronisation master or access point. */
|
||||
WAPI_MODE_REPEAT = IW_MODE_REPEAT, /* Wireless repeater, forwarder. */
|
||||
WAPI_MODE_SECOND = IW_MODE_SECOND, /* Secondary master/repeater, backup. */
|
||||
WAPI_MODE_MONITOR = IW_MODE_MONITOR, /* Passive monitor, listen only. */
|
||||
WAPI_MODE_MESH = IW_MODE_MESH /* Mesh (IEEE 802.11s) network */
|
||||
} wapi_mode_t;
|
||||
|
||||
/* Bitrate flags.
|
||||
@ -293,19 +291,6 @@ int wapi_get_netmask(int sock, const char *ifname, struct in_addr *addr);
|
||||
|
||||
int wapi_set_netmask(int sock, const char *ifname, const struct in_addr *addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_routes
|
||||
*
|
||||
* Description:
|
||||
* Parses routing table rows from WAPI_PROC_NET_ROUTE.
|
||||
*
|
||||
* Input Parameters:
|
||||
* list - Pushes collected wapi_route_info_t into this list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_routes(wapi_list_t * list);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_add_route_gw
|
||||
*
|
||||
@ -336,22 +321,6 @@ int wapi_del_route_gw(int sock, wapi_route_target_t targettype,
|
||||
FAR const struct in_addr *gw);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_we_version
|
||||
*
|
||||
* Description:
|
||||
* Gets kernel WE (Wireless Extensions) version.
|
||||
*
|
||||
* Input Parameters:
|
||||
* we_version Set to we_version_compiled of range information.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_we_version(int sock, const char *ifname, FAR int *we_version);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_freq
|
||||
*
|
||||
@ -572,19 +541,6 @@ int wapi_set_txpower(int sock, FAR const char *ifname, int power,
|
||||
|
||||
int wapi_make_socket(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_ifnames
|
||||
*
|
||||
* Description:
|
||||
* Parses WAPI_PROC_NET_WIRELESS.
|
||||
*
|
||||
* Returned Value:
|
||||
* list Pushes collected wapi_string_t into this list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_ifnames(FAR wapi_list_t *list);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_scan_init
|
||||
*
|
||||
|
@ -21,10 +21,6 @@ config WIRELESS_WAPI_CMDTOOL
|
||||
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"
|
||||
|
@ -40,12 +40,12 @@
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# LM-75 Temperature Sensor Application
|
||||
# IEEE802.11 Wapi Application
|
||||
|
||||
CONFIG_WIRELESS_WAPI_PRIORITY ?= 100
|
||||
CONFIG_WIRELESS_WAPI_STACKSIZE ?= 2048
|
||||
|
||||
APPNAME = temp
|
||||
APPNAME = wapi
|
||||
PRIORITY = $(CONFIG_WIRELESS_WAPI_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_WIRELESS_WAPI_STACKSIZE)
|
||||
|
||||
@ -84,7 +84,7 @@ else
|
||||
INSTALL_DIR = $(BIN_DIR)
|
||||
endif
|
||||
|
||||
CONFIG_WAPI_PROGNAME ?= lm75$(EXEEXT)
|
||||
CONFIG_WAPI_PROGNAME ?= wapi$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_WAPI_PROGNAME)
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
@ -121,7 +121,7 @@ endif
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),lm75_main)
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
|
||||
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||
else
|
||||
|
@ -1,8 +1,13 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/examples/network.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
* Copyright (C) 2011, 2017Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Adapted for Nuttx from WAPI:
|
||||
*
|
||||
* 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:
|
||||
@ -287,116 +292,6 @@ int wapi_set_netmask(int sock, FAR const char *ifname,
|
||||
return wapi_set_addr(sock, ifname, SIOCSIFNETMASK, addr);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_routes
|
||||
*
|
||||
* Description:
|
||||
* Parses routing table rows from WAPI_PROC_NET_ROUTE.
|
||||
*
|
||||
* Input Parameters:
|
||||
* list - Pushes collected wapi_route_info_t into this list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_routes(FAR wapi_list_t *list)
|
||||
{
|
||||
FAR FILE *fp;
|
||||
size_t bufsiz = WAPI_PROC_LINE_SIZE * sizeof(char);
|
||||
char buf[WAPI_PROC_LINE_SIZE];
|
||||
int ret;
|
||||
|
||||
WAPI_VALIDATE_PTR(list);
|
||||
|
||||
/* Open file for reading. */
|
||||
|
||||
fp = fopen(WAPI_PROC_NET_ROUTE, "r");
|
||||
if (!fp)
|
||||
{
|
||||
WAPI_STRERROR("fopen(\"%s\", \"r\")", WAPI_PROC_NET_ROUTE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Skip header line. */
|
||||
|
||||
if (!fgets(buf, bufsiz, fp))
|
||||
{
|
||||
WAPI_ERROR("Invalid \"%s\" content!\n", WAPI_PROC_NET_ROUTE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Read lines. */
|
||||
|
||||
ret = 0;
|
||||
while (fgets(buf, bufsiz, fp))
|
||||
{
|
||||
wapi_route_info_t *ri;
|
||||
char ifname[WAPI_PROC_LINE_SIZE];
|
||||
int refcnt, use, metric, mtu, window, irtt;
|
||||
unsigned int dest, gw, flags, netmask;
|
||||
|
||||
/* Allocate route row buffer. */
|
||||
|
||||
ri = malloc(sizeof(wapi_route_info_t));
|
||||
if (!ri)
|
||||
{
|
||||
WAPI_STRERROR("malloc()");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Read and tokenize fields. */
|
||||
|
||||
sscanf(buf, "%s\t" /* ifname */
|
||||
"%x\t" /* dest */
|
||||
"%x\t" /* gw */
|
||||
"%x\t" /* flags */
|
||||
"%d\t" /* refcnt */
|
||||
"%d\t" /* use */
|
||||
"%d\t" /* metric */
|
||||
"%x\t" /* mask */
|
||||
"%d\t" /* mtu */
|
||||
"%d\t" /* window */
|
||||
"%d\t", /* irtt */
|
||||
ifname, &dest, &gw, &flags, &refcnt, &use, &metric, &netmask, &mtu,
|
||||
&window, &irtt);
|
||||
|
||||
/* Allocate "ifname". */
|
||||
|
||||
ri->ifname = malloc((strlen(ifname) + 1) * sizeof(char));
|
||||
if (!ri->ifname)
|
||||
{
|
||||
WAPI_STRERROR("malloc()");
|
||||
free(ri);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy fields. */
|
||||
|
||||
sprintf(ri->ifname, "%s", ifname);
|
||||
ri->dest.s_addr = dest;
|
||||
ri->gw.s_addr = gw;
|
||||
ri->flags = flags;
|
||||
ri->refcnt = refcnt;
|
||||
ri->use = use;
|
||||
ri->metric = metric;
|
||||
ri->netmask.s_addr = netmask;
|
||||
ri->mtu = mtu;
|
||||
ri->window = window;
|
||||
ri->irtt = irtt;
|
||||
|
||||
/* Push parsed node to the list. */
|
||||
|
||||
ri->next = list->head.route;
|
||||
list->head.route = ri;
|
||||
}
|
||||
|
||||
/* Close file. */
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_add_route_gw
|
||||
*
|
||||
|
@ -1,8 +1,13 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/src/util.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
* Copyright (C) 2011, 2017Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Adapted for Nuttx from WAPI:
|
||||
*
|
||||
* 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:
|
||||
@ -46,8 +51,30 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define WAPI_IOCTL_COMMAND_NAMEBUFSIZ 128 /* Is fairly enough to print an
|
||||
* integer. */
|
||||
/* The address family that we used to create the socket really does not
|
||||
* matter. It should, however, be valid in the current configuration.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_NET_IPv4)
|
||||
# define PF_INETX PF_INET
|
||||
#elif defined(CONFIG_NET_IPv6)
|
||||
# define PF_INETX PF_INET6
|
||||
#endif
|
||||
|
||||
/* SOCK_DGRAM is the preferred socket type to use when we just want a
|
||||
* socket for performing driver ioctls. However, we can't use SOCK_DRAM
|
||||
* if UDP is disabled.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_UDP
|
||||
# define SOCK_WAPI SOCK_DGRAM
|
||||
#else
|
||||
# define SOCK_WAPI SOCK_STREAM
|
||||
#endif
|
||||
|
||||
/* Size of the command buffer */
|
||||
|
||||
#define WAPI_IOCTL_COMMAND_NAMEBUFSIZ 24
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
@ -72,91 +99,11 @@ static char g_ioctl_command_namebuf[WAPI_IOCTL_COMMAND_NAMEBUFSIZ];
|
||||
|
||||
int wapi_make_socket(void)
|
||||
{
|
||||
return socket(AF_INET, SOCK_DGRAM, 0);
|
||||
return socket(PF_INETX, SOCK_WAPI, 0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_ifnames
|
||||
*
|
||||
* Description:
|
||||
* Parses WAPI_PROC_NET_WIRELESS.
|
||||
*
|
||||
* Returned Value:
|
||||
* list Pushes collected wapi_string_t into this list.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_ifnames(FAR wapi_list_t *list)
|
||||
{
|
||||
FILE *fp;
|
||||
int ret;
|
||||
size_t tmpsize = WAPI_PROC_LINE_SIZE * sizeof(char);
|
||||
char tmp[WAPI_PROC_LINE_SIZE];
|
||||
|
||||
WAPI_VALIDATE_PTR(list);
|
||||
|
||||
/* Open file for reading. */
|
||||
|
||||
fp = fopen(WAPI_PROC_NET_WIRELESS, "r");
|
||||
if (!fp)
|
||||
{
|
||||
WAPI_STRERROR("fopen(\"%s\", \"r\")", WAPI_PROC_NET_WIRELESS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Skip first two lines. */
|
||||
|
||||
if (!fgets(tmp, tmpsize, fp) || !fgets(tmp, tmpsize, fp))
|
||||
{
|
||||
WAPI_ERROR("Invalid \"%s\" content!\n", WAPI_PROC_NET_WIRELESS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Iterate over available lines. */
|
||||
|
||||
ret = 0;
|
||||
while (fgets(tmp, tmpsize, fp))
|
||||
{
|
||||
char *beg;
|
||||
char *end;
|
||||
wapi_string_t *string;
|
||||
|
||||
/* Locate the interface name region. */
|
||||
|
||||
for (beg = tmp; *beg && isspace(*beg); beg++);
|
||||
for (end = beg; *end && *end != ':'; end++);
|
||||
|
||||
/* Allocate both wapi_string_t and char vector. */
|
||||
|
||||
string = malloc(sizeof(wapi_string_t));
|
||||
if (string)
|
||||
{
|
||||
string->data = malloc(end - beg + sizeof(char));
|
||||
}
|
||||
|
||||
if (!string || !string->data)
|
||||
{
|
||||
WAPI_STRERROR("malloc()");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Copy region into the buffer. */
|
||||
|
||||
snprintf(string->data, (end - beg + sizeof(char)), "%s", beg);
|
||||
|
||||
/* Push string into the list. */
|
||||
|
||||
string->next = list->head.string;
|
||||
list->head.string = string;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_ifnames
|
||||
* Name: wapi_ioctl_command_name
|
||||
*
|
||||
* Description:
|
||||
* Return name string for IOCTL command
|
||||
|
@ -1,8 +1,13 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/src/util.h
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
* Copyright (C) 2011, 2017Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Adapted for Nuttx from WAPI:
|
||||
*
|
||||
* 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:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,13 @@
|
||||
/****************************************************************************
|
||||
* apps/wireless/wapi/src/wireless.c
|
||||
*
|
||||
* Copyright (c) 2010, Volkan YAZICI <volkan.yazici@gmail.com>
|
||||
* All rights reserved.
|
||||
* Copyright (C) 2011, 2017Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Adapted for Nuttx from WAPI:
|
||||
*
|
||||
* 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:
|
||||
@ -32,30 +37,25 @@
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <nuttx/net/arp.h>
|
||||
#include <nuttx/wireless/wireless.h>
|
||||
|
||||
#include "wireless/wapi.h"
|
||||
#include "util.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef LIBNL1
|
||||
# define nl_sock nl_handle
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Events & Streams */
|
||||
|
||||
struct iw_event_stream_s
|
||||
struct wapi_event_stream_s
|
||||
{
|
||||
FAR char *end; /* End of the stream */
|
||||
FAR char *current; /* Current event in stream of events */
|
||||
@ -92,7 +92,8 @@ FAR const char *g_wapi_modes[] =
|
||||
"WAPI_MODE_MASTER",
|
||||
"WAPI_MODE_REPEAT",
|
||||
"WAPI_MODE_SECOND",
|
||||
"WAPI_MODE_MONITOR"
|
||||
"WAPI_MODE_MONITOR",
|
||||
"WAPI_MODE_MESH"
|
||||
};
|
||||
|
||||
/* Bit Rate */
|
||||
@ -174,7 +175,7 @@ static int wapi_parse_mode(int iw_mode, FAR wapi_mode_t *wapi_mode)
|
||||
return 0;
|
||||
|
||||
default:
|
||||
WAPI_ERROR("Unknown mode: %d.\n", iw_mode);
|
||||
WAPI_ERROR("ERROR: Unknown mode: %d\n", iw_mode);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -194,32 +195,35 @@ static int wapi_make_ether(FAR struct ether_addr *addr, int byte)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: iw_event_stream_init
|
||||
* Name: wapi_event_stream_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize a stream to access the events.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void iw_event_stream_init(FAR struct iw_event_stream_s *stream,
|
||||
FAR char *data, size_t len)
|
||||
static void wapi_event_stream_init(FAR struct wapi_event_stream_s *stream,
|
||||
FAR char *data, size_t len)
|
||||
{
|
||||
memset(stream, 0, sizeof(struct iw_event_stream_s));
|
||||
memset(stream, 0, sizeof(struct wapi_event_stream_s));
|
||||
stream->current = data;
|
||||
stream->end = &data[len];
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: iw_event_stream_pop
|
||||
* Name: wapi_event_stream_extract
|
||||
*
|
||||
* Description:
|
||||
* Extract the next event from the stream.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int iw_event_stream_pop(FAR struct iw_event_stream_s *stream,
|
||||
FAR struct iw_event *iwe, int we_version)
|
||||
static int wapi_event_stream_extract(FAR struct wapi_event_stream_s *stream,
|
||||
FAR struct iw_event *iwe)
|
||||
{
|
||||
return iw_extract_event_stream((struct stream_descr *)stream, iwe,
|
||||
we_version);
|
||||
#warning Missing logic
|
||||
// return iw_extract_event_stream((struct stream_descr *)stream, iwe, 0);
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -319,51 +323,6 @@ static int wapi_scan_event(FAR struct iw_event *event, FAR wapi_list_t *list)
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_we_version
|
||||
*
|
||||
* Description:
|
||||
* Gets kernel WE (Wireless Extensions) version.
|
||||
*
|
||||
* Input Parameters:
|
||||
* we_version Set to we_version_compiled of range information.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_we_version(int sock, const char *ifname, FAR int *we_version)
|
||||
{
|
||||
struct iwreq wrq;
|
||||
char buf[sizeof(struct iw_range) * 2];
|
||||
int ret;
|
||||
|
||||
WAPI_VALIDATE_PTR(we_version);
|
||||
|
||||
/* Prepare request. */
|
||||
|
||||
bzero(buf, sizeof(buf));
|
||||
wrq.u.data.pointer = buf;
|
||||
wrq.u.data.length = sizeof(buf);
|
||||
wrq.u.data.flags = 0;
|
||||
|
||||
/* Get WE version. */
|
||||
|
||||
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
|
||||
if ((ret = ioctl(sock, SIOCGIWRANGE, (unsigned long)((uintptr_t)&wrq))) >= 0)
|
||||
{
|
||||
struct iw_range *range = (struct iw_range *)buf;
|
||||
*we_version = (int)range->we_version_compiled;
|
||||
}
|
||||
else
|
||||
{
|
||||
WAPI_IOCTL_STRERROR(SIOCGIWRANGE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: wapi_get_freq
|
||||
*
|
||||
@ -373,7 +332,7 @@ int wapi_get_we_version(int sock, const char *ifname, FAR int *we_version)
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
|
||||
FAR wapi_freq_flag_t *flag);
|
||||
FAR wapi_freq_flag_t *flag)
|
||||
{
|
||||
struct iwreq wrq;
|
||||
int ret;
|
||||
@ -396,7 +355,7 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
|
||||
}
|
||||
else
|
||||
{
|
||||
WAPI_ERROR("Unknown flag: %d.\n", wrq.u.freq.flags);
|
||||
WAPI_ERROR("ERROR: Unknown flag: %d\n", wrq.u.freq.flags);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -416,8 +375,8 @@ int wapi_get_freq(int sock, FAR const char *ifname, FAR double *freq,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int wapi_set_freq(int sock, FARconst char *ifname, double freq,
|
||||
wapi_freq_flag_t flag);
|
||||
int wapi_set_freq(int sock, FAR const char *ifname, double freq,
|
||||
wapi_freq_flag_t flag)
|
||||
{
|
||||
struct iwreq wrq;
|
||||
int ret;
|
||||
@ -799,19 +758,22 @@ int wapi_get_bitrate(int sock, FAR const char *ifname,
|
||||
if ((ret = ioctl(sock, SIOCGIWRATE, (unsigned long)((uintptr_t)&wrq))) >= 0)
|
||||
{
|
||||
/* Check if enabled. */
|
||||
|
||||
if (wrq.u.bitrate.disabled)
|
||||
{
|
||||
WAPI_ERROR("Bitrate is disabled.\n");
|
||||
WAPI_ERROR("ERROR: Bitrate is disabled\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Get bitrate. */
|
||||
|
||||
*bitrate = wrq.u.bitrate.value;
|
||||
*flag = wrq.u.bitrate.fixed ? WAPI_BITRATE_FIXED : WAPI_BITRATE_AUTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
WAPI_IOCTL_STRERROR(SIOCGIWRATE);
|
||||
WAPI_IOCTL_STRERROR(SIOCGIWRATE);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -912,7 +874,7 @@ int wapi_get_txpower(int sock, FAR const char *ifname, FAR int *power,
|
||||
}
|
||||
else
|
||||
{
|
||||
WAPI_ERROR("Unknown flag: %d.\n", wrq.u.txpower.flags);
|
||||
WAPI_ERROR("ERROR: Unknown flag: %d\n", wrq.u.txpower.flags);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -937,7 +899,7 @@ 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);
|
||||
wapi_txpower_flag_t flag)
|
||||
{
|
||||
struct iwreq wrq;
|
||||
int ret;
|
||||
@ -1063,18 +1025,10 @@ int wapi_scan_coll(int sock, FAR const char *ifname, FAR wapi_list_t *aps)
|
||||
FAR char *buf;
|
||||
int buflen;
|
||||
struct iwreq wrq;
|
||||
int we_version;
|
||||
int ret;
|
||||
|
||||
WAPI_VALIDATE_PTR(aps);
|
||||
|
||||
/* Get WE version. (Required for event extraction via libiw.) */
|
||||
|
||||
if ((ret = wapi_get_we_version(sock, ifname, &we_version)) < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
buflen = IW_SCAN_MAX_DATA;
|
||||
buf = malloc(buflen * sizeof(char));
|
||||
if (!buf)
|
||||
@ -1087,13 +1041,14 @@ alloc:
|
||||
/* Collect results. */
|
||||
|
||||
wrq.u.data.pointer = buf;
|
||||
wrq.u.data.length = buflen;
|
||||
wrq.u.data.flags = 0;
|
||||
wrq.u.data.length = buflen;
|
||||
wrq.u.data.flags = 0;
|
||||
strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
|
||||
if ((ret = ioctl(sock, SIOCGIWSCAN, (unsigned long)((uintptr_t)&wrq))) < 0 &&
|
||||
errno == E2BIG)
|
||||
|
||||
ret = ioctl(sock, SIOCGIWSCAN, (unsigned long)((uintptr_t)&wrq));
|
||||
if (ret < 0 && errno == E2BIG)
|
||||
{
|
||||
char *tmp;
|
||||
FAR char *tmp;
|
||||
|
||||
buflen *= 2;
|
||||
tmp = realloc(buf, buflen);
|
||||
@ -1124,12 +1079,14 @@ alloc:
|
||||
if (wrq.u.data.length)
|
||||
{
|
||||
struct iw_event iwe;
|
||||
struct iw_event_stream_s stream;
|
||||
struct wapi_event_stream_s stream;
|
||||
|
||||
iw_event_stream_init(&stream, buf, wrq.u.data.length);
|
||||
wapi_event_stream_init(&stream, buf, wrq.u.data.length);
|
||||
do
|
||||
{
|
||||
if ((ret = iw_event_stream_pop(&stream, &iwe, we_version)) >= 0)
|
||||
/* Get the next event from the stream */
|
||||
|
||||
if ((ret = wapi_event_stream_extract(&stream, &iwe)) >= 0)
|
||||
{
|
||||
int eventret = wapi_scan_event(&iwe, aps);
|
||||
if (eventret < 0)
|
||||
@ -1139,7 +1096,7 @@ alloc:
|
||||
}
|
||||
else
|
||||
{
|
||||
WAPI_ERROR("iw_event_stream_pop() failed!\n");
|
||||
WAPI_ERROR("ERROR: wapi_event_stream_extract() failed!\n");
|
||||
}
|
||||
}
|
||||
while (ret > 0);
|
||||
|
Loading…
Reference in New Issue
Block a user