From ddb9ea4a932c0b6b516df810155a0233fd05452b Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sat, 11 Nov 2017 17:16:36 +0000 Subject: [PATCH 01/12] Update Makefile --- esp32/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esp32/Makefile b/esp32/Makefile index 90049b647e..ed0f7acc4b 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -61,6 +61,8 @@ CFLAGS = $(CFLAGS_XTENSA) $(CFLAGS_XTENSA_OPT) -nostdlib -std=gnu99 -g3 -ggdb -f LDFLAGS = -nostdlib -Wl,-Map=$(@:.elf=.map) -Wl,--no-check-sections -u call_user_start_cpu0 LDFLAGS += -Wl,-static -Wl,--undefined=uxTopUsedPriority -Wl,--gc-sections +INC=$(ESP_IDF_PATH)/components/esp32/include + LIBS = -L$(ESP_IDF_COMP_PATH)/esp32/lib -L$(ESP_IDF_COMP_PATH)/esp32/ld -L$(ESP_IDF_COMP_PATH)/bt/lib \ -L$(ESP_IDF_COMP_PATH)/esp32 -L$(ESP_IDF_COMP_PATH)/newlib/lib -Lbootloader \ -Llib -lnvs_flash -ltcpip_adapter -L$(BUILD) -lhal -lcore -lwps -lcoexist \ From 252b8e1a7ccd7148225ba82779c5b3927b291b36 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sat, 11 Nov 2017 17:25:34 +0000 Subject: [PATCH 02/12] Update Makefile --- esp32/Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/esp32/Makefile b/esp32/Makefile index ed0f7acc4b..90049b647e 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -61,8 +61,6 @@ CFLAGS = $(CFLAGS_XTENSA) $(CFLAGS_XTENSA_OPT) -nostdlib -std=gnu99 -g3 -ggdb -f LDFLAGS = -nostdlib -Wl,-Map=$(@:.elf=.map) -Wl,--no-check-sections -u call_user_start_cpu0 LDFLAGS += -Wl,-static -Wl,--undefined=uxTopUsedPriority -Wl,--gc-sections -INC=$(ESP_IDF_PATH)/components/esp32/include - LIBS = -L$(ESP_IDF_COMP_PATH)/esp32/lib -L$(ESP_IDF_COMP_PATH)/esp32/ld -L$(ESP_IDF_COMP_PATH)/bt/lib \ -L$(ESP_IDF_COMP_PATH)/esp32 -L$(ESP_IDF_COMP_PATH)/newlib/lib -Lbootloader \ -Llib -lnvs_flash -ltcpip_adapter -L$(BUILD) -lhal -lcore -lwps -lcoexist \ From c8ce36de8ee7a32761a65808552582a34fb7428b Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sat, 11 Nov 2017 22:55:51 +0000 Subject: [PATCH 03/12] Update modwlan.c Added hostname configuration --- esp32/mods/modwlan.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index b28a8486d1..f5fe0f9cd9 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -53,6 +53,9 @@ #include "freertos/task.h" #include "freertos/event_groups.h" +#include "tcpip_adapter.h" + + /****************************************************************************** DEFINE TYPES ******************************************************************************/ @@ -218,6 +221,10 @@ void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, if (mode != WIFI_MODE_STA) { wlan_setup_ap (ssid, auth, key, channel, add_mac); + tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "Dickmunch_STA"); + } + else { + tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "Dickmunch_AP"); } esp_wifi_start(); From 2c138eeb3160f7aa6a5430aa19fdc5c3d3227863 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:03:29 +0000 Subject: [PATCH 04/12] Update modwlan.h --- esp32/mods/modwlan.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esp32/mods/modwlan.h b/esp32/mods/modwlan.h index 4737a16ea3..24d399d892 100644 --- a/esp32/mods/modwlan.h +++ b/esp32/mods/modwlan.h @@ -53,6 +53,7 @@ typedef struct _wlan_obj_t { uint8_t ssid[(MODWLAN_SSID_LEN_MAX + 1)]; uint8_t key[65]; uint8_t mac[6]; + uint8_t hostname[16]; // the sssid (or name) and mac of the other device uint8_t ssid_o[33]; @@ -74,7 +75,7 @@ extern wlan_obj_t wlan_obj; DECLARE PUBLIC FUNCTIONS ******************************************************************************/ extern void wlan_pre_init (void); -extern void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac); +extern void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac, char *hostname); extern void wlan_update(void); extern void wlan_get_mac (uint8_t *macAddress); extern void wlan_get_ip (uint32_t *ip); From 55b936a875b70acbf1d148504f172967d43b45eb Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:06:36 +0000 Subject: [PATCH 05/12] Update modwlan.c --- esp32/mods/modwlan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index f5fe0f9cd9..348c6c8b57 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -202,7 +202,7 @@ void wlan_pre_init (void) { wlan_obj.base.type = (mp_obj_t)&mod_network_nic_type_wlan; } -void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac) { +void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac, char *hostname) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); From 4087c55b5116832bc65b67399ef5acc7d31106e7 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:11:39 +0000 Subject: [PATCH 06/12] Update mptask.c --- esp32/mptask.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/esp32/mptask.c b/esp32/mptask.c index 9e280938cc..860cc71426 100644 --- a/esp32/mptask.c +++ b/esp32/mptask.c @@ -410,8 +410,7 @@ STATIC void mptask_update_lpwan_mac_address (void) { #endif STATIC void mptask_enable_wifi_ap (void) { - wlan_setup (WIFI_MODE_AP, DEFAULT_AP_SSID, WIFI_AUTH_WPA2_PSK, DEFAULT_AP_PASSWORD, - DEFAULT_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, true); + wlan_setup (WIFI_MODE_AP, DEFAULT_AP_SSID, WIFI_AUTH_WPA2_PSK, DEFAULT_AP_PASSWORD, DEFAULT_AP_CHANNEL, ANTENNA_TYPE_INTERNAL, true, "illysky"); mod_network_register_nic(&wlan_obj); } From e14d6ab5dee86f990fcc52a96d69547e306c165f Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:31:58 +0000 Subject: [PATCH 07/12] Update modwlan.c --- esp32/mods/modwlan.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 348c6c8b57..01b1a32abc 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -154,6 +154,7 @@ STATIC void wlan_validate_mode (uint mode); STATIC void wlan_set_mode (uint mode); STATIC void wlan_setup_ap (const char *ssid, uint32_t auth, const char *key, uint32_t channel, bool add_mac); STATIC void wlan_validate_ssid_len (uint32_t len); +STATIC void wlan_validate_hostname_len (uint32_t len); STATIC uint32_t wlan_set_ssid_internal (const char *ssid, uint8_t len, bool add_mac); STATIC void wlan_validate_security (uint8_t auth, const char *key); STATIC void wlan_set_security_internal (uint8_t auth, const char *key); @@ -401,6 +402,12 @@ STATIC void wlan_validate_ssid_len (uint32_t len) { } } +STATIC void wlan_validate_hostname_len (uint32_t len) { + if (len > 16) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, mpexception_value_invalid_arguments)); + } +} + STATIC uint32_t wlan_set_ssid_internal (const char *ssid, uint8_t len, bool add_mac) { // save the ssid memcpy(&wlan_obj.ssid, ssid, len); @@ -662,6 +669,13 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { wlan_obj.pwrsave = args[5].u_bool; + // get the hostname + const char *hostname = NULL; + if (args[7].u_obj != NULL) { + hostname = mp_obj_str_get_str(args[7].u_obj); + wlan_validate_host_len(strlen(hostname)); + } + if (mode != WIFI_MODE_STA) { if (ssid == NULL) { nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "AP SSID not given")); @@ -672,7 +686,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { } // initialize the wlan subsystem - wlan_setup(mode, (const char *)ssid, auth, (const char *)key, channel, antenna, false); + wlan_setup(mode, (const char *)ssid, auth, (const char *)key, channel, antenna, false, (const char *)hostname); mod_network_register_nic(&wlan_obj); return mp_const_none; @@ -686,7 +700,9 @@ STATIC const mp_arg_t wlan_init_args[] = { { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, { MP_QSTR_antenna, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = ANTENNA_TYPE_INTERNAL} }, { MP_QSTR_power_save, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + { MP_QSTR_hostname, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; + STATIC mp_obj_t wlan_make_new(const mp_obj_type_t *type, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *all_args) { // parse args mp_map_t kw_args; From aa75d045f027727fd8f630ab9b54b2e5cd9a07e3 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:34:53 +0000 Subject: [PATCH 08/12] Update modwlan.c --- esp32/mods/modwlan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 01b1a32abc..61dcef66e3 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -673,7 +673,7 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { const char *hostname = NULL; if (args[7].u_obj != NULL) { hostname = mp_obj_str_get_str(args[7].u_obj); - wlan_validate_host_len(strlen(hostname)); + wlan_validate_hostname_len(strlen(hostname)); } if (mode != WIFI_MODE_STA) { From db8c5697dbff29d2f4ac375944fedb9cd90a16f6 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:37:53 +0000 Subject: [PATCH 09/12] Update modwlan.c --- esp32/mods/modwlan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 61dcef66e3..462707b844 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -203,7 +203,7 @@ void wlan_pre_init (void) { wlan_obj.base.type = (mp_obj_t)&mod_network_nic_type_wlan; } -void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac, char *hostname) { +void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac, const char *hostname) { wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); ESP_ERROR_CHECK(esp_wifi_init(&cfg)); From 417886e5a60bde4d62a06cfd484b27c085b2b6a0 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:38:27 +0000 Subject: [PATCH 10/12] Update modwlan.h --- esp32/mods/modwlan.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/mods/modwlan.h b/esp32/mods/modwlan.h index 24d399d892..cd3582f653 100644 --- a/esp32/mods/modwlan.h +++ b/esp32/mods/modwlan.h @@ -75,7 +75,7 @@ extern wlan_obj_t wlan_obj; DECLARE PUBLIC FUNCTIONS ******************************************************************************/ extern void wlan_pre_init (void); -extern void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac, char *hostname); +extern void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, uint32_t channel, uint32_t antenna, bool add_mac, const char *hostname); extern void wlan_update(void); extern void wlan_get_mac (uint8_t *macAddress); extern void wlan_get_ip (uint32_t *ip); From 9b909fefe6947785cf2970dc7f65686a0173dcee Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 00:43:34 +0000 Subject: [PATCH 11/12] Update modwlan.c --- esp32/mods/modwlan.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 462707b844..08be67e5f8 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -220,12 +220,14 @@ void wlan_setup (int32_t mode, const char *ssid, uint32_t auth, const char *key, wlan_set_antenna(antenna); wlan_set_mode(mode); + // Add hostname + if (mode != WIFI_MODE_STA) { wlan_setup_ap (ssid, auth, key, channel, add_mac); - tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "Dickmunch_STA"); + tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_AP, hostname); } else { - tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, "Dickmunch_AP"); + tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, hostname); } esp_wifi_start(); From 67c07c1548d143a3a5ef63537021554c8bdccc07 Mon Sep 17 00:00:00 2001 From: Dominic Moffat Date: Sun, 12 Nov 2017 01:47:58 +0000 Subject: [PATCH 12/12] Update modwlan.c --- esp32/mods/modwlan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 08be67e5f8..0481bcd2bc 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -673,8 +673,8 @@ STATIC mp_obj_t wlan_init_helper(wlan_obj_t *self, const mp_arg_val_t *args) { // get the hostname const char *hostname = NULL; - if (args[7].u_obj != NULL) { - hostname = mp_obj_str_get_str(args[7].u_obj); + if (args[6].u_obj != NULL) { + hostname = mp_obj_str_get_str(args[6].u_obj); wlan_validate_hostname_len(strlen(hostname)); }