wapi: Add pscan cmd to trigger a passive scan.
Added scanning in passive mode without affecting the scan command. Signed-off-by: xuchaojie <xuchaojie@xiaomi.com>
This commit is contained in:
parent
a16fb23dd7
commit
ca5293629f
@ -707,6 +707,31 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname,
|
|||||||
FAR const char *essid,
|
FAR const char *essid,
|
||||||
uint8_t *channels, int num_channels);
|
uint8_t *channels, int num_channels);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: wapi_escan_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Starts a extended scan on the given interface, you can specify the scan
|
||||||
|
* type. Root privileges are required to start a scan.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int wapi_escan_init(int sock, FAR const char *ifname,
|
||||||
|
uint8_t scan_type, FAR const char *essid);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: wapi_escan_channel_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Starts a scan on the given interface. Root privileges are required to
|
||||||
|
* start a scan with specified channels.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int wapi_escan_channel_init(int sock, FAR const char *ifname,
|
||||||
|
uint8_t scan_type, FAR const char *essid,
|
||||||
|
uint8_t *channels, int num_channels);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: wapi_scan_stat
|
* Name: wapi_scan_stat
|
||||||
*
|
*
|
||||||
|
@ -97,6 +97,7 @@ static int wapi_bitrate_cmd (int sock, int argc, FAR char **argv);
|
|||||||
static int wapi_txpower_cmd (int sock, int argc, FAR char **argv);
|
static int wapi_txpower_cmd (int sock, int argc, FAR char **argv);
|
||||||
static int wapi_scan_results_cmd (int sock, int argc, FAR char **argv);
|
static int wapi_scan_results_cmd (int sock, int argc, FAR char **argv);
|
||||||
static int wapi_scan_cmd (int sock, int argc, FAR char **argv);
|
static int wapi_scan_cmd (int sock, int argc, FAR char **argv);
|
||||||
|
static int wapi_pscan_cmd (int sock, int argc, FAR char **argv);
|
||||||
static int wapi_country_cmd (int sock, int argc, FAR char **argv);
|
static int wapi_country_cmd (int sock, int argc, FAR char **argv);
|
||||||
static int wapi_sense_cmd (int sock, int argc, FAR char **argv);
|
static int wapi_sense_cmd (int sock, int argc, FAR char **argv);
|
||||||
#ifdef CONFIG_WIRELESS_WAPI_INITCONF
|
#ifdef CONFIG_WIRELESS_WAPI_INITCONF
|
||||||
@ -114,6 +115,7 @@ static const struct wapi_command_s g_wapi_commands[] =
|
|||||||
{"help", 0, 0, NULL},
|
{"help", 0, 0, NULL},
|
||||||
{"show", 1, 1, wapi_show_cmd},
|
{"show", 1, 1, wapi_show_cmd},
|
||||||
{"scan", 1, 2, wapi_scan_cmd},
|
{"scan", 1, 2, wapi_scan_cmd},
|
||||||
|
{"pscan", 1, 2, wapi_pscan_cmd},
|
||||||
{"scan_results", 1, 1, wapi_scan_results_cmd},
|
{"scan_results", 1, 1, wapi_scan_results_cmd},
|
||||||
{"ip", 2, 2, wapi_ip_cmd},
|
{"ip", 2, 2, wapi_ip_cmd},
|
||||||
{"mask", 2, 2, wapi_mask_cmd},
|
{"mask", 2, 2, wapi_mask_cmd},
|
||||||
@ -833,7 +835,8 @@ static int wapi_scan_results_cmd(int sock, int argc, FAR char **argv)
|
|||||||
* Name: wapi_scan_cmd
|
* Name: wapi_scan_cmd
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Scans available APs in the range using given ifname interface.
|
* Use the given ifname interface and active mode to scan the APs
|
||||||
|
* available in the range.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* None
|
* None
|
||||||
@ -849,7 +852,37 @@ static int wapi_scan_cmd(int sock, int argc, FAR char **argv)
|
|||||||
|
|
||||||
/* Start scan */
|
/* Start scan */
|
||||||
|
|
||||||
ret = wapi_scan_init(sock, argv[0], essid);
|
ret = wapi_escan_init(sock, argv[0], IW_SCAN_TYPE_ACTIVE, essid);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wapi_scan_results_cmd(sock, 1, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: wapi_pscan_cmd
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Use the given ifname interface and passive mode to scan the APs
|
||||||
|
* available in the range.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int wapi_pscan_cmd(int sock, int argc, FAR char **argv)
|
||||||
|
{
|
||||||
|
FAR const char *essid;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
essid = argc > 1 ? argv[1] : NULL;
|
||||||
|
|
||||||
|
/* Start scan */
|
||||||
|
|
||||||
|
ret = wapi_escan_init(sock, argv[0], IW_SCAN_TYPE_PASSIVE, essid);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
||||||
@ -1095,6 +1128,7 @@ static void wapi_showusage(FAR const char *progname, int exitcode)
|
|||||||
fprintf(stderr, "Usage:\n");
|
fprintf(stderr, "Usage:\n");
|
||||||
fprintf(stderr, "\t%s show <ifname>\n", progname);
|
fprintf(stderr, "\t%s show <ifname>\n", progname);
|
||||||
fprintf(stderr, "\t%s scan <ifname>\n", progname);
|
fprintf(stderr, "\t%s scan <ifname>\n", progname);
|
||||||
|
fprintf(stderr, "\t%s pscan <ifname>\n", progname);
|
||||||
fprintf(stderr, "\t%s scan_results <ifname>\n", progname);
|
fprintf(stderr, "\t%s scan_results <ifname>\n", progname);
|
||||||
fprintf(stderr, "\t%s ip <ifname> <IP address>\n", progname);
|
fprintf(stderr, "\t%s ip <ifname> <IP address>\n", progname);
|
||||||
fprintf(stderr, "\t%s mask <ifname> <mask>\n", progname);
|
fprintf(stderr, "\t%s mask <ifname> <mask>\n", progname);
|
||||||
|
@ -1183,6 +1183,23 @@ int wapi_set_txpower(int sock, FAR const char *ifname, int power,
|
|||||||
int wapi_scan_channel_init(int sock, FAR const char *ifname,
|
int wapi_scan_channel_init(int sock, FAR const char *ifname,
|
||||||
FAR const char *essid,
|
FAR const char *essid,
|
||||||
uint8_t *channels, int num_channels)
|
uint8_t *channels, int num_channels)
|
||||||
|
{
|
||||||
|
return wapi_escan_channel_init(sock, ifname, IW_SCAN_TYPE_ACTIVE, essid,
|
||||||
|
channels, num_channels);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: wapi_escan_channel_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Starts a scan on the given interface. Root privileges are required to
|
||||||
|
* start a scan with specified channels.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int wapi_escan_channel_init(int sock, FAR const char *ifname,
|
||||||
|
uint8_t scan_type, FAR const char *essid,
|
||||||
|
uint8_t *channels, int num_channels)
|
||||||
{
|
{
|
||||||
struct iw_scan_req req;
|
struct iw_scan_req req;
|
||||||
struct iwreq wrq =
|
struct iwreq wrq =
|
||||||
@ -1193,16 +1210,13 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname,
|
|||||||
int ret;
|
int ret;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
memset(&req, 0, sizeof(req));
|
||||||
|
|
||||||
if (essid && (essid_len = strlen(essid)) > 0)
|
if (essid && (essid_len = strlen(essid)) > 0)
|
||||||
{
|
{
|
||||||
memset(&req, 0, sizeof(req));
|
req.essid_len = essid_len;
|
||||||
req.essid_len = essid_len;
|
|
||||||
req.bssid.sa_family = ARPHRD_ETHER;
|
|
||||||
memset(req.bssid.sa_data, 0xff, IFHWADDRLEN);
|
|
||||||
memcpy(req.essid, essid, essid_len);
|
memcpy(req.essid, essid, essid_len);
|
||||||
wrq.u.data.pointer = (caddr_t)&req;
|
wrq.u.data.flags = IW_SCAN_THIS_ESSID;
|
||||||
wrq.u.data.length = sizeof(req);
|
|
||||||
wrq.u.data.flags = IW_SCAN_THIS_ESSID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channels && num_channels > 0)
|
if (channels && num_channels > 0)
|
||||||
@ -1214,6 +1228,12 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.scan_type = scan_type;
|
||||||
|
req.bssid.sa_family = ARPHRD_ETHER;
|
||||||
|
memset(req.bssid.sa_data, 0xff, IFHWADDRLEN);
|
||||||
|
wrq.u.data.pointer = (caddr_t)&req;
|
||||||
|
wrq.u.data.length = sizeof(req);
|
||||||
|
|
||||||
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
|
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
|
||||||
ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq));
|
ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -1240,6 +1260,21 @@ int wapi_scan_init(int sock, FAR const char *ifname, FAR const char *essid)
|
|||||||
return wapi_scan_channel_init(sock, ifname, essid, NULL, 0);
|
return wapi_scan_channel_init(sock, ifname, essid, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: wapi_escan_init
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Starts a extended scan on the given interface, you can specify the scan
|
||||||
|
* type. Root privileges are required to start a scan.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int wapi_escan_init(int sock, FAR const char *ifname,
|
||||||
|
uint8_t scan_type, FAR const char *essid)
|
||||||
|
{
|
||||||
|
return wapi_escan_channel_init(sock, ifname, scan_type, essid, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: wapi_scan_stat
|
* Name: wapi_scan_stat
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user