This is an automated email from the ASF dual-hosted git repository.
jerpelea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new bd9174a wireless/wapi: add set country code support
bd9174a is described below
commit bd9174a3b639c2db60cbbc73c9f0260ab17bee5b
Author: chao.an <[email protected]>
AuthorDate: Mon Jan 4 17:53:19 2021 +0800
wireless/wapi: add set country code support
Signed-off-by: chao.an <[email protected]>
---
include/wireless/wapi.h | 11 +++++++++++
wireless/wapi/src/wapi.c | 18 ++++++++++++++++++
wireless/wapi/src/wireless.c | 34 ++++++++++++++++++++++++++++++++++
3 files changed, 63 insertions(+)
diff --git a/include/wireless/wapi.h b/include/wireless/wapi.h
index 8c3df1a..77b4fda 100644
--- a/include/wireless/wapi.h
+++ b/include/wireless/wapi.h
@@ -700,6 +700,17 @@ int wapi_scan_coll(int sock, FAR const char *ifname,
void wapi_scan_coll_free(FAR struct wapi_list_s *aps);
/****************************************************************************
+ * Name: wapi_set_country
+ *
+ * Description:
+ * Set the country code
+ *
+ ****************************************************************************/
+
+int wapi_set_country(int sock, FAR const char *ifname,
+ FAR const char *country);
+
+/****************************************************************************
* Name: wapi_get_sensitivity
*
* Description:
diff --git a/wireless/wapi/src/wapi.c b/wireless/wapi/src/wapi.c
index b0c6f5f..2e1ef96 100644
--- a/wireless/wapi/src/wapi.c
+++ b/wireless/wapi/src/wapi.c
@@ -96,6 +96,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_country_cmd (int sock, int argc, FAR char **argv);
#ifdef CONFIG_WIRELESS_WAPI_INITCONF
static int wapi_reconnect_cmd (int sock, int argc, FAR char **argv);
static int wapi_save_config_cmd (int sock, int argc, FAR char **argv);
@@ -121,6 +122,7 @@ static const struct wapi_command_s g_wapi_commands[] =
{"ap", 2, 2, wapi_ap_cmd},
{"bitrate", 3, 3, wapi_bitrate_cmd},
{"txpower", 3, 3, wapi_txpower_cmd},
+ {"country", 2, 2, wapi_country_cmd},
#ifdef CONFIG_WIRELESS_WAPI_INITCONF
{"reconnect", 1, 1, wapi_reconnect_cmd},
{"save_config", 1, 1, wapi_save_config_cmd},
@@ -745,6 +747,22 @@ static int wapi_scan_cmd(int sock, int argc, FAR char
**argv)
return wapi_scan_results_cmd(sock, 1, argv);
}
+/****************************************************************************
+ * Name: wapi_country_cmd
+ *
+ * Description:
+ * Set the country code
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static int wapi_country_cmd(int sock, int argc, FAR char **argv)
+{
+ return wapi_set_country(sock, argv[0], argv[1]);
+}
+
#ifdef CONFIG_WIRELESS_WAPI_INITCONF
/****************************************************************************
diff --git a/wireless/wapi/src/wireless.c b/wireless/wapi/src/wireless.c
index 9ddec6d..d507012 100644
--- a/wireless/wapi/src/wireless.c
+++ b/wireless/wapi/src/wireless.c
@@ -1394,6 +1394,40 @@ void wapi_scan_coll_free(FAR struct wapi_list_s *list)
}
/****************************************************************************
+ * Name: wapi_set_country
+ *
+ * Description:
+ * Set the country code
+ *
+ ****************************************************************************/
+
+int wapi_set_country(int sock, FAR const char *ifname,
+ FAR const char *country)
+{
+ struct iwreq wrq =
+ {
+ };
+
+ int ret;
+
+ /* Prepare request. */
+
+ wrq.u.data.pointer = (FAR void *)country;
+ wrq.u.data.length = 2;
+
+ strncpy(wrq.ifr_name, ifname, IFNAMSIZ);
+ ret = ioctl(sock, SIOCSIWCOUNTRY, (unsigned long)((uintptr_t)&wrq));
+ if (ret < 0)
+ {
+ int errcode = errno;
+ WAPI_IOCTL_STRERROR(SIOCSIWCOUNTRY, errcode);
+ ret = -errcode;
+ }
+
+ return ret;
+}
+
+/****************************************************************************
* Name: wapi_get_sensitivity
*
* Description: