diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h index 4f8ed9cf2..d4cf69036 100644 --- a/include/wireless/wapi.h +++ b/include/wireless/wapi.h @@ -707,6 +707,31 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname, FAR const char *essid, 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 * diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c index f5b35142c..fe65d99f2 100644 --- a/wireless/wapi/src/wapi.c +++ b/wireless/wapi/src/wapi.c @@ -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_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_pscan_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); #ifdef CONFIG_WIRELESS_WAPI_INITCONF @@ -114,6 +115,7 @@ static const struct wapi_command_s g_wapi_commands[] = {"help", 0, 0, NULL}, {"show", 1, 1, wapi_show_cmd}, {"scan", 1, 2, wapi_scan_cmd}, + {"pscan", 1, 2, wapi_pscan_cmd}, {"scan_results", 1, 1, wapi_scan_results_cmd}, {"ip", 2, 2, wapi_ip_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 * * 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: * None @@ -849,7 +852,37 @@ static int wapi_scan_cmd(int sock, int argc, FAR char **argv) /* 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) { return ret; @@ -1095,6 +1128,7 @@ static void wapi_showusage(FAR const char *progname, int exitcode) fprintf(stderr, "Usage:\n"); fprintf(stderr, "\t%s show \n", progname); fprintf(stderr, "\t%s scan \n", progname); + fprintf(stderr, "\t%s pscan \n", progname); fprintf(stderr, "\t%s scan_results \n", progname); fprintf(stderr, "\t%s ip \n", progname); fprintf(stderr, "\t%s mask \n", progname); diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c index 87bfb4d0b..f7b9f08b0 100644 --- a/wireless/wapi/src/wireless.c +++ b/wireless/wapi/src/wireless.c @@ -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, FAR const char *essid, 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 iwreq wrq = @@ -1193,16 +1210,13 @@ int wapi_scan_channel_init(int sock, FAR const char *ifname, int ret; int i; + memset(&req, 0, sizeof(req)); + if (essid && (essid_len = strlen(essid)) > 0) { - memset(&req, 0, sizeof(req)); - req.essid_len = essid_len; - req.bssid.sa_family = ARPHRD_ETHER; - memset(req.bssid.sa_data, 0xff, IFHWADDRLEN); + req.essid_len = essid_len; memcpy(req.essid, essid, essid_len); - wrq.u.data.pointer = (caddr_t)&req; - wrq.u.data.length = sizeof(req); - wrq.u.data.flags = IW_SCAN_THIS_ESSID; + wrq.u.data.flags = IW_SCAN_THIS_ESSID; } 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); ret = ioctl(sock, SIOCSIWSCAN, (unsigned long)((uintptr_t)&wrq)); 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); } +/**************************************************************************** + * 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 *