wireless/wapi: Remove functionality that depends on the Linux procfs: This includes only 1) listing of available interfaces and 2) listing of all routes.

This commit is contained in:
Gregory Nutt 2017-04-10 16:02:17 -06:00
parent 2d73f735fe
commit 322ffe193b
6 changed files with 43 additions and 302 deletions

View File

@ -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
@ -293,19 +290,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
*
@ -572,19 +556,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
*

View File

@ -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
*

View File

@ -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:
@ -76,87 +81,7 @@ 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)
{
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

View File

@ -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:

View File

@ -1,8 +1,13 @@
/****************************************************************************
* apps/wireless/wapi/src/wapi.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:
@ -321,71 +326,6 @@ int wapi_main(int argc, char *argv[])
ifname = argv[1];
/* Get ifnames */
bzero(&list, sizeof(wapi_list_t));
ret = wapi_get_ifnames(&list);
printf("wapi_get_ifnames(): ret: %d", ret);
if (ret >= 0)
{
FAR wapi_string_t *str;
/* Print ifnames */
printf(", ifnames:");
for (str = list.head.string; str; str = str->next)
{
printf(" %s", str->data);
}
/* Free ifnames */
str = list.head.string;
while (str)
{
FAR wapi_string_t *tmp;
tmp = str->next;
free(str->data);
free(str);
str = tmp;
}
}
putchar('\n');
/* Get routes */
bzero(&list, sizeof(wapi_list_t));
ret = wapi_get_routes(&list);
printf("wapi_get_routes(): ret: %d\n", ret);
if (ret >= 0)
{
wapi_route_info_t *ri;
/* Print route */
for (ri = list.head.route; ri; ri = ri->next)
{
printf(">> dest: %s, gw: %s, netmask: %s\n",
inet_ntoa(ri->dest), inet_ntoa(ri->gw),
inet_ntoa(ri->netmask));
}
/* Free routes */
ri = list.head.route;
while (ri)
{
FAR wapi_route_info_t *tmpri;
tmpri = ri->next;
free(ri->ifname);
free(ri);
ri = tmpri;
}
}
/* Make a comm. sock. */
sock = wapi_make_socket();

View File

@ -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: