diff --git a/MicroPython_BUILD/components/libssh2/src/libssh2_config.h b/MicroPython_BUILD/components/libssh2/src/libssh2_config.h index 5b27748..8e18131 100644 --- a/MicroPython_BUILD/components/libssh2/src/libssh2_config.h +++ b/MicroPython_BUILD/components/libssh2/src/libssh2_config.h @@ -34,6 +34,10 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2DEBUG +#define HAVE_GETTIMEOFDAY +#define LIBSSH2_DH_GEX_NEW + /* Headers */ #define LIBSSH2_MBEDTLS #define HAVE_O_NONBLOCK diff --git a/MicroPython_BUILD/components/micropython/esp32/help.c b/MicroPython_BUILD/components/micropython/esp32/help.c index 95d115c..7751797 100644 --- a/MicroPython_BUILD/components/micropython/esp32/help.c +++ b/MicroPython_BUILD/components/micropython/esp32/help.c @@ -27,11 +27,16 @@ */ #include "py/builtin.h" +#include "sdkconfig.h" const char esp32_help_text[] = -"Welcome to MicroPython on the ESP32!\n" +#if CONFIG_SPIRAM_SUPPORT +"Welcome to LoBo MicroPython on the ESP32 with psRAM!\n" +#else +"Welcome to LoBo MicroPython on the ESP32!\n" +#endif "\n" -"For generic online docs please visit http://docs.micropython.org/\n" +"For online documentation please visit:\nhttps://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki\n" "\n" "For access to the hardware use the 'machine' module:\n" "\n" diff --git a/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.c b/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.c index c01281a..3935856 100644 --- a/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.c +++ b/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.c @@ -1,3 +1,28 @@ +/* + * This file is part of the LoBo MicroPython project + * + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 LoBo (https://gihub.com/loboris) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #include "sdkconfig.h" @@ -9,13 +34,13 @@ #include "libs/espcurl.h" #include "libs/libGSM.h" -#include "libssh2.h" #include "lwip/err.h" #include "lwip/sockets.h" #include "lwip/sys.h" #include "lwip/netdb.h" #include "lwip/dns.h" #include "esp_log.h" +#include "esp_task_wdt.h" #include "mphalport.h" #include "esp_wifi_types.h" @@ -24,25 +49,6 @@ #include "py/mpthread.h" #include "py/nlr.h" -// Set default values for configuration variables -uint8_t curl_verbose = 1; // show detailed info of what curl functions are doing -uint8_t curl_progress = 1; // show progress during transfers -uint16_t curl_timeout = 60; // curl operations timeout in seconds -uint32_t curl_maxbytes = 300000; // limit download length -uint8_t curl_initialized = 0; -uint8_t curl_nodecode = 1; - -#if CONFIG_SPIRAM_SUPPORT -int hdr_maxlen = 1024; -int body_maxlen = 4096; -#else -int hdr_maxlen = 512; -int body_maxlen = 1024; -#endif - -const char *CURL_TAG = "[Curl]"; - - //-------------------- void checkConnection() { @@ -61,6 +67,24 @@ void checkConnection() #ifdef CONFIG_MICROPY_USE_CURL +const char *CURL_TAG = "[Curl]"; + +// Set default values for configuration variables +uint8_t curl_verbose = 0; // show detailed info of what curl functions are doing +uint8_t curl_progress = 0; // show progress during curl transfers +uint16_t curl_timeout = 60; // curl operations timeout in seconds +uint32_t curl_maxbytes = 300000; // limit download length +uint8_t curl_initialized = 0; +uint8_t curl_nodecode = 1; + +#if CONFIG_SPIRAM_SUPPORT +int hdr_maxlen = 1024; +int body_maxlen = 4096; +#else +int hdr_maxlen = 512; +int body_maxlen = 1024; +#endif + static uint8_t curl_sim_fs = 0; struct curl_Transfer { @@ -102,6 +126,8 @@ static size_t curlWrite(void *buffer, size_t size, size_t nmemb, void *userdata) double curtime = 0; curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime); + mp_hal_reset_wdt(); + if (!s->tofile) { // === Downloading to buffer === char *buf = (char *)buffer; @@ -160,6 +186,8 @@ static size_t curlRead(void *ptr, size_t size, size_t nmemb, void *userdata) curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime); size_t nread; + mp_hal_reset_wdt(); + if (curl_sim_fs) { if (s->len < 1024) { size_t reqsize = size*nmemb; @@ -264,11 +292,11 @@ int Curl_GET(char *url, char *fname, char *hdr, char *body, int hdrlen, int body FILE* file = NULL; int err = 0; - if ((hdr) && (hdrlen < MIN_HDR_BODY_BUF_LEN)) { + if ((hdr) && (hdrlen < MIN_HDR_BUF_LEN)) { err = -1; goto exit; } - if ((body) && (bodylen < MIN_HDR_BODY_BUF_LEN)) { + if ((body) && (bodylen < MIN_BODY_BUF_LEN)) { err = -2; goto exit; } @@ -369,11 +397,11 @@ int Curl_POST(char *url , char *hdr, char *body, int hdrlen, int bodylen) struct curl_slist *headerlist=NULL; const char hl_buf[] = "Expect:"; - if ((hdr) && (hdrlen < MIN_HDR_BODY_BUF_LEN)) { + if ((hdr) && (hdrlen < MIN_HDR_BUF_LEN)) { err = -1; goto exit; } - if ((body) && (bodylen < MIN_HDR_BODY_BUF_LEN)) { + if ((body) && (bodylen < MIN_BODY_BUF_LEN)) { err = -2; goto exit; } @@ -457,11 +485,11 @@ int Curl_FTP(uint8_t upload, char *url, char *user_pass, char *fname, char *hdr, FILE* file = NULL; int fsize = 0; - if ((hdr) && (hdrlen < MIN_HDR_BODY_BUF_LEN)) { + if ((hdr) && (hdrlen < MIN_HDR_BUF_LEN)) { err = -1; goto exit; } - if ((body) && (bodylen < MIN_HDR_BODY_BUF_LEN)) { + if ((body) && (bodylen < MIN_BODY_BUF_LEN)) { err = -2; goto exit; } @@ -608,12 +636,29 @@ void Curl_cleanup() { } } -#endif +#endif // CONFIG_MICROPY_USE_CURL #ifdef CONFIG_MICROPY_USE_SSH +#include "libssh2.h" #include "libssh2_sftp.h" +const char *SSH_TAG = "[SSH]"; + +uint8_t ssh2_verbose = 0; // show detailed info of what ssh2 functions are doing +uint8_t ssh2_progress = 0; // show progress during ssh2 transfers +uint16_t ssh2_session_trace = 0; +uint8_t ssh2_session_timeout = 8; +uint32_t ssh2_maxbytes = 300000; // limit download length + +#if CONFIG_SPIRAM_SUPPORT +int ssh2_hdr_maxlen = 1024; +int ssh2_body_maxlen = 4096; +#else +int ssh2_hdr_maxlen = 512; +int ssh2_body_maxlen = 1024; +#endif + // ==== LIBSSH2 functions ==== //------------------------------------------------------------ @@ -626,7 +671,7 @@ static int waitsocket(int socket_fd, LIBSSH2_SESSION *session) fd_set *readfd = NULL; int dir; - timeout.tv_sec = 10; + timeout.tv_sec = 5; timeout.tv_usec = 0; FD_ZERO(&fd); @@ -652,15 +697,15 @@ static void _append_msg(char *messages, char *msg, int msglen, uint8_t type) strcat(messages, msg); strcat(messages, "\n"); } - if (curl_verbose) { + if (ssh2_verbose) { if (type == ESP_LOG_ERROR) { - ESP_LOGE(CURL_TAG, "%s", msg); + ESP_LOGE(SSH_TAG, "%s", msg); } else if (type == ESP_LOG_WARN) { - ESP_LOGW(CURL_TAG, "%s", msg); + ESP_LOGW(SSH_TAG, "%s", msg); } else if (type == ESP_LOG_INFO) { - ESP_LOGI(CURL_TAG, "%s", msg); + ESP_LOGI(SSH_TAG, "%s", msg); } } } @@ -714,8 +759,8 @@ static int sock_connect(char *server, char *port, char *messages, int msglen) return sock; } -//---------------------------------------------------------------------------------------------------------------------- -static LIBSSH2_SESSION *getSSHSession(int sock, char *username, char *password, int auth_pw, char *messages, int msglen) +//--------------------------------------------------------------------------------------------------------------------------------------------------- +static LIBSSH2_SESSION *getSSHSession(int sock, char *username, char *password, char* privkey, char *pubkey, int auth_pw, char *messages, int msglen) { int rc; const char *fingerprint; @@ -732,9 +777,27 @@ static LIBSSH2_SESSION *getSSHSession(int sock, char *username, char *password, sprintf(msg, "* SSH session created"); _append_msg(messages, msg, msglen, ESP_LOG_INFO); + // Set trace level + libssh2_trace(session, ssh2_session_trace); + + // Set timeout, reset wdt first + mp_hal_set_wdt_tmo(); + #ifdef CONFIG_MICROPY_USE_TASK_WDT + esp_task_wdt_reset(); + #endif + #if CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 || CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 + vTaskDelay(1); // allow other core idle task to reset the watchdog + #endif + libssh2_session_set_timeout(session, ssh2_session_timeout*1000); + + // Set preferred key exchange methods + //libssh2_session_method_pref(session, LIBSSH2_METHOD_KEX, "diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1"); + // ... start it up. This will trade welcome banners, exchange keys, and setup crypto, compression, and MAC layers rc = libssh2_session_handshake(session, sock); if (rc) { + libssh2_session_disconnect(session, "Error Shutdown."); + libssh2_session_free(session); sprintf(msg, "* Failure establishing SSH session: %d", rc); _append_msg(messages, msg, msglen, ESP_LOG_ERROR); return NULL; @@ -747,17 +810,42 @@ static LIBSSH2_SESSION *getSSHSession(int sock, char *username, char *password, * may have it hard coded, may go to a file, may present it to the * user, that's your call */ - fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); - sprintf(msg, "* Fingerprint: ["); - for(int i = 0; i < 20; i++) { - sprintf(msg+15+(i*3), "%02X ", (unsigned char)fingerprint[i]); + int fplen = 0, fpofst = 0; + fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA256); + if (fingerprint) { + fplen = 32; + fpofst = 25; + sprintf(msg, "* Fingerprint (SHA256): ["); + } + else { + fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1); + if (fingerprint) { + fplen = 20; + fpofst = 23; + sprintf(msg, "* Fingerprint (SHA1): ["); + } + else { + fingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_MD5); + if (fingerprint) { + fplen = 16; + fpofst = 22; + sprintf(msg, "* Fingerprint (MD5): ["); + } + } + } + if (fplen > 0) { + for(int i = 0; i < fplen; i++) { + sprintf(msg+fpofst+(i*2), "%02X", (unsigned char)fingerprint[i]); + } + strcat(msg, "]"); + _append_msg(messages, msg, msglen, ESP_LOG_INFO); } - strcat(msg, "]"); - _append_msg(messages, msg, msglen, ESP_LOG_INFO); if (auth_pw) { // We could authenticate via password if (libssh2_userauth_password(session, username, password)) { + libssh2_session_disconnect(session, "Error Shutdown."); + libssh2_session_free(session); sprintf(msg, "* Authentication by password failed."); _append_msg(messages, msg, msglen, ESP_LOG_ERROR); return NULL; @@ -767,7 +855,9 @@ static LIBSSH2_SESSION *getSSHSession(int sock, char *username, char *password, } else { // Or by public key - if (libssh2_userauth_publickey_fromfile(session, username, ".ssh/id_rsa.pub", ".ssh/id_rsa", password)) { + if (libssh2_userauth_publickey_fromfile(session, username, pubkey, privkey, password)) { + libssh2_session_disconnect(session, "Error Shutdown."); + libssh2_session_free(session); sprintf(msg, "* Authentication by public key failed"); _append_msg(messages, msg, msglen, ESP_LOG_ERROR); return NULL; @@ -800,7 +890,7 @@ static int sshDownload(LIBSSH2_CHANNEL *channel, libssh2_struct_stat *fileinfo, if (fdd != NULL) { // === Downloading to file === if (err == 0) { - if ((got + amount) < curl_maxbytes) { + if ((got + amount) < ssh2_maxbytes) { size_t nwrite = fwrite(mem, 1, amount, fdd); if (nwrite <= 0) { sprintf(msg, "* Download: Error writing to file at %u", (uint32_t)got); @@ -838,19 +928,19 @@ static int sshDownload(LIBSSH2_CHANNEL *channel, libssh2_struct_stat *fileinfo, break; } got += rc; - if (curl_progress) { + if (ssh2_progress) { if (tlatest == 0) { printf("\n"); tlatest = mp_hal_ticks_ms(); } - if ((tlatest + (curl_progress*1000)) >= mp_hal_ticks_ms()) { + if ((tlatest + (ssh2_progress*1000)) >= mp_hal_ticks_ms()) { tlatest = mp_hal_ticks_ms(); printf("Download: %u\r", (uint32_t)got); } } } tstart = mp_hal_ticks_ms() - tstart; - if (curl_progress) { + if (ssh2_progress) { printf(" \r"); } sprintf(msg, "* Received: %u bytes in %0.1f sec (%0.3f KB/s)", (uint32_t)got, (float)(tstart / 1000.0), (float)((float)(got)/1024.0/((float)(tstart) / 1000.0))); @@ -883,6 +973,7 @@ static int sshUpload(LIBSSH2_CHANNEL *channel, FILE *fdd, char *hdr, int hdrlen) if (rc < 0) { sprintf(msg, "* Upload: Error sending: %d at %u", rc, sent); _append_msg(hdr, msg, hdrlen, ESP_LOG_ERROR); + err = -10; break; } else { @@ -891,12 +982,12 @@ static int sshUpload(LIBSSH2_CHANNEL *channel, FILE *fdd, char *hdr, int hdrlen) nread -= rc; sent += rc; } - if (curl_progress) { + if (ssh2_progress) { if (tlatest == 0) { printf("\n"); tlatest = mp_hal_ticks_ms(); } - if ((tlatest + (curl_progress*1000)) >= mp_hal_ticks_ms()) { + if ((tlatest + (ssh2_progress*1000)) >= mp_hal_ticks_ms()) { tlatest = mp_hal_ticks_ms(); printf("Upload: %u\r", sent); } @@ -905,7 +996,7 @@ static int sshUpload(LIBSSH2_CHANNEL *channel, FILE *fdd, char *hdr, int hdrlen) } while (1); tstart = mp_hal_ticks_ms() - tstart; - if (curl_progress) { + if (ssh2_progress) { printf(" \r"); } sprintf(msg, "* Sent: %u bytes in %0.1f sec (%0.3f KB/s)", sent, (float)(tstart / 1000.0), (float)((float)(sent)/1024.0/((float)(tstart) / 1000.0))); @@ -918,8 +1009,8 @@ static int sshUpload(LIBSSH2_CHANNEL *channel, FILE *fdd, char *hdr, int hdrlen) return err; } -//------------------------------------------------------------------------------------------------------------------------------------------------------ -int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, char *pass, char *fname, char *hdr, char *body, int hdrlen, int bodylen) +//----------------------------------------------------------------------------------------------------------------------------------------------------------------- +int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, char *pass, char *key, char *fname, char *hdr, char *body, int hdrlen, int bodylen) { char msg[80]; @@ -929,8 +1020,31 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, int fsize = 0; hdrlen -=1; bodylen -=1; + int auth = 1; + char pub_key[128]; + char *privkey = NULL; + char *pubkey = NULL; + if (key) { + // Check the authentication keys + struct stat sb_key; + if ((stat(key, &sb_key) != 0) || (sb_key.st_size = 0)) { + sprintf(msg, "* Error opening private key file"); + _append_msg(hdr, msg, hdrlen, ESP_LOG_ERROR); + return -5; + } + sprintf(pub_key, key); + strcat(pub_key, ".pub"); + if ((stat(pub_key, &sb_key) != 0) || (sb_key.st_size = 0)) { + sprintf(msg, "* Error opening public key file"); + _append_msg(hdr, msg, hdrlen, ESP_LOG_ERROR); + return -5; + } + privkey = key; + pubkey = pub_key; + auth = 0; + } - if ((fname) && ((type == 0) || (type == 1))){ + if ((fname) && ((type == 0) || (type == 1))){ if (strcmp(fname, "simulate") != 0) { if (type == 1) { // Uploading the file @@ -967,20 +1081,22 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, libssh2_exit(); return -2; } + vTaskDelay(50 / portTICK_RATE_MS); // ** Create session - session = getSSHSession(sock, user, pass, 1, hdr, hdrlen); + session = getSSHSession(sock, user, pass, privkey, pubkey, auth, hdr, hdrlen); if (session == NULL) { if (fdd) fclose(fdd); close(sock); libssh2_exit(); return -3; } + vTaskDelay(100 / portTICK_RATE_MS); LIBSSH2_CHANNEL *channel = NULL; // ** Open session if (type == 1) { - // SCP File upload + // === SCP File upload === channel = libssh2_scp_send(session, scppath, 0555, (unsigned long)fsize); if (!channel) { char *errmsg; @@ -993,9 +1109,13 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, } // ** Upload a file via SCP rc = sshUpload(channel, fdd, hdr, hdrlen); + if (fdd != NULL) { + if (rc) sprintf(body, "Uploaded file %s", fname); + else sprintf(body, "Error uploading file %s", fname); + } } else if (type == 0) { - // SCP File download + // === SCP File download === channel = libssh2_scp_recv2(session, scppath, &fileinfo); if (!channel) { sprintf(msg, "* Unable to open a session: %d", libssh2_session_last_errno(session)); @@ -1004,15 +1124,19 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, goto shutdown; } - if (fileinfo.st_size > curl_maxbytes) { - sprintf(msg, "* Warning: file size (%u) > max allowed (%u) !", (uint32_t)fileinfo.st_size, curl_maxbytes); + if (fileinfo.st_size > ssh2_maxbytes) { + sprintf(msg, "* Warning: file size (%u) > max allowed (%u) !", (uint32_t)fileinfo.st_size, ssh2_maxbytes); _append_msg(hdr, msg, hdrlen, ESP_LOG_ERROR); } // ** Download a file via SCP rc = sshDownload(channel, &fileinfo, fdd, hdr, body, hdrlen, bodylen); + if (fdd != NULL) { + if (rc) sprintf(body, "Downloaded file %s", fname); + else sprintf(body, "Error downloading file %s", fname); + } } else if (type == 5) { - // SSH exec, Exec non-blocking on the remove host + // === SSH exec, Execute non-blocking on the remove host === int bytecount = 0; char *exitsignal=(char *)"none"; @@ -1029,6 +1153,7 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, _append_msg(hdr, msg, hdrlen, ESP_LOG_INFO); while( (rc = libssh2_channel_exec(channel, scppath)) == LIBSSH2_ERROR_EAGAIN ) { + vTaskDelay(2 / portTICK_RATE_MS); waitsocket(sock, session); } if ( rc != 0 ) { @@ -1077,7 +1202,7 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, } } else if (type == 4) { - // SFTP mkdir + // === SFTP mkdir === LIBSSH2_SFTP *sftp_session; sftp_session = libssh2_sftp_init(session); @@ -1086,6 +1211,7 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, _append_msg(hdr, msg, hdrlen, ESP_LOG_ERROR); goto shutdown; } + vTaskDelay(20 / portTICK_RATE_MS); // Since we have not set non-blocking, tell libssh2 we are blocking libssh2_session_set_blocking(session, 1); // Make a directory via SFTP @@ -1101,11 +1227,12 @@ int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, libssh2_sftp_shutdown(sftp_session); } else if ((type == 2) || (type == 3)) { - // SFTP List + // === SFTP List === LIBSSH2_SFTP *sftp_session; LIBSSH2_SFTP_HANDLE *sftp_handle; sftp_session = libssh2_sftp_init(session); + vTaskDelay(20 / portTICK_RATE_MS); if (!sftp_session) { sprintf(msg, "Unable to init SFTP session\n"); _append_msg(hdr, msg, hdrlen, ESP_LOG_ERROR); @@ -1177,13 +1304,13 @@ shutdown: libssh2_session_free(session); close(sock); libssh2_exit(); - if (curl_verbose) { - ESP_LOGI(CURL_TAG, "All done"); + if (ssh2_verbose) { + ESP_LOGI(SSH_TAG, "All done"); } return rc; } -#endif +#endif // CONFIG_MICROPY_USE_SSH -#endif +#endif // defined(CONFIG_MICROPY_USE_CURL) || defined(CONFIG_MICROPY_USE_SSH) diff --git a/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.h b/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.h index e1183da..d035efd 100644 --- a/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.h +++ b/MicroPython_BUILD/components/micropython/esp32/libs/espcurl.h @@ -1,3 +1,28 @@ +/* + * This file is part of the LoBo MicroPython project + * + * The MIT License (MIT) + * + * Copyright (c) 2017-2018 LoBo (https://gihub.com/loboris) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #ifndef _ESPCURL_H_ @@ -8,12 +33,23 @@ #if defined(CONFIG_MICROPY_USE_CURL) || defined(CONFIG_MICROPY_USE_SSH) #include + +#define MIN_HDR_BUF_LEN 128 +#define MIN_BODY_BUF_LEN 256 + +// ================ +// Public functions +// ================ + +#ifdef CONFIG_MICROPY_USE_CURL + #include "curl/curl.h" -#define MIN_HDR_BODY_BUF_LEN 256 -#define GMAIL_SMTP "smtp.gmail.com" -#define GMAIL_PORT 465 +#define GMAIL_SMTP "smtp.gmail.com" +#define GMAIL_PORT 465 +struct curl_httppost *formpost; +struct curl_httppost *lastptr; // Some configuration variables extern uint8_t curl_verbose; // show detailed info of what curl functions are doing @@ -22,20 +58,9 @@ extern uint16_t curl_timeout; // curl operations timeout in seconds extern uint32_t curl_maxbytes; // limit download length extern uint8_t curl_initialized; extern uint8_t curl_nodecode; - extern int hdr_maxlen; extern int body_maxlen; -struct curl_httppost *formpost; -struct curl_httppost *lastptr; - - -// ================ -// Public functions -// ================ - -#ifdef CONFIG_MICROPY_USE_CURL - /* * ---------------------------------------------------------- * int res = Curl_GET(url, fname, hdr, body, hdrlen, bodylen) @@ -117,21 +142,29 @@ int Curl_FTP(uint8_t upload, char *url, char *user_pass, char *fname, char *hdr, #endif -#endif +#endif //CONFIG_MICROPY_USE_CURL //================== void Curl_cleanup(); #ifdef CONFIG_MICROPY_USE_SSH -//======================================================================================================================================================= -int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, char *pass, char *fname, char *hdr, char *body, int hdrlen, int bodylen); +extern uint8_t ssh2_verbose; +extern uint8_t ssh2_progress; +extern uint16_t ssh2_session_trace; +extern uint8_t ssh2_session_timeout; +extern int ssh2_hdr_maxlen; +extern int ssh2_body_maxlen; +extern uint32_t ssh2_maxbytes; -#endif +//================================================================================================================================================================== +int ssh_SCP(uint8_t type, char *server, char *port, char * scppath, char *user, char *pass, char *key, char *fname, char *hdr, char *body, int hdrlen, int bodylen); + +#endif // CONFIG_MICROPY_USE_SSH //===================== void checkConnection(); -#endif +#endif // defined(CONFIG_MICROPY_USE_CURL) || defined(CONFIG_MICROPY_USE_SSH) #endif diff --git a/MicroPython_BUILD/components/micropython/esp32/main.c b/MicroPython_BUILD/components/micropython/esp32/main.c index c3c4ad9..a5aeb0f 100644 --- a/MicroPython_BUILD/components/micropython/esp32/main.c +++ b/MicroPython_BUILD/components/micropython/esp32/main.c @@ -154,6 +154,7 @@ soft_reset: else printf("Error mounting Flash file system\n"); // === Print some info === + char sbuff[24] = { 0 }; gc_info_t info; gc_info(&info); // set gc.threshold to 87.5% of usable heap @@ -172,17 +173,20 @@ soft_reset: // Print partition info const esp_partition_t *running_partition = esp_ota_get_running_partition(); if (running_partition != NULL) { - printf("Running from %spartition at %X, type %X [%s].\n", - ((running_partition->encrypted) ? "encrypted " : ""), running_partition->address, running_partition->subtype, running_partition->label); + if (running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) sprintf(sbuff, "Factory "); + else if (running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0) sprintf(sbuff, "OTA_0 "); + else if (running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_1) sprintf(sbuff, "OTA_1 "); + else sbuff[0] = '\0'; + printf("Running from %s%spartition starting at 0x%X, [%s].\n", + ((running_partition->encrypted) ? "encrypted " : ""), sbuff, running_partition->address, running_partition->label); } - char rst_reason[24] = { 0 }; - mpsleep_get_reset_desc(rst_reason); + mpsleep_get_reset_desc(sbuff); if (mpsleep_get_wake_reason() != MPSLEEP_NONE_WAKE) printf(" "); - printf("\n Reset reason: %s\n", rst_reason); + printf("\n Reset reason: %s\n", sbuff); if (mpsleep_get_wake_reason() != MPSLEEP_NONE_WAKE) { - mpsleep_get_wake_desc(rst_reason); - printf("Wakeup source: %s\n", rst_reason); + mpsleep_get_wake_desc(sbuff); + printf("Wakeup source: %s\n", sbuff); } printf(" uPY stack: %d bytes\n", MP_TASK_STACK_LEN-1024); diff --git a/MicroPython_BUILD/components/micropython/esp32/modcurl.c b/MicroPython_BUILD/components/micropython/esp32/modcurl.c index 63db367..068bac6 100644 --- a/MicroPython_BUILD/components/micropython/esp32/modcurl.c +++ b/MicroPython_BUILD/components/micropython/esp32/modcurl.c @@ -129,8 +129,8 @@ STATIC mp_obj_t curl_Options(size_t n_args, const mp_obj_t *pos_args, mp_map_t * if (args[ARG_progress].u_int >= 0) curl_progress = args[ARG_progress].u_int; if (args[ARG_timeout].u_int >= 10) curl_timeout = args[ARG_timeout].u_int; if (args[ARG_maxfsize].u_int > 1000) curl_maxbytes = args[ARG_maxfsize].u_int; - if (args[ARG_hdrlen].u_int > 128) hdr_maxlen = args[ARG_hdrlen].u_int; - if (args[ARG_bodylen].u_int > MIN_HDR_BODY_BUF_LEN) body_maxlen = args[ARG_bodylen].u_int; + if (args[ARG_hdrlen].u_int > MIN_HDR_BUF_LEN) hdr_maxlen = args[ARG_hdrlen].u_int; + if (args[ARG_bodylen].u_int > MIN_BODY_BUF_LEN) body_maxlen = args[ARG_bodylen].u_int; if (args[ARG_nodecode].u_int >= 0) curl_nodecode = args[ARG_nodecode].u_int & 1; if (args[ARG_print].u_bool) { @@ -176,7 +176,7 @@ STATIC mp_obj_t curl_GET(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a } fname = fullname; } - body_len = MIN_HDR_BODY_BUF_LEN; + body_len = MIN_BODY_BUF_LEN; } vstr_init_len(&header, hdr_len); @@ -476,7 +476,7 @@ STATIC mp_obj_t curl_FTP_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_ } fname = fullname; } - body_len = MIN_HDR_BODY_BUF_LEN; + body_len = MIN_BODY_BUF_LEN; } else if (type == 1) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Expected file name for PUT command")); @@ -489,7 +489,7 @@ STATIC mp_obj_t curl_FTP_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_ body.buf[0] = '\0'; MP_THREAD_GIL_EXIT(); - res = Curl_FTP(type&1, url, user, fname, header.buf, body.buf, header.len, body.len); + res = Curl_FTP(type&1, url, userpass, fname, header.buf, body.buf, header.len, body.len); MP_THREAD_GIL_ENTER(); mp_obj_t tuple[3]; @@ -530,19 +530,20 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(curl_FTP_LIST_obj, 3, curl_FTP_LIST); STATIC const mp_rom_map_elem_t curl_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_curl) }, - { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&curl_info_obj) }, - { MP_ROM_QSTR(MP_QSTR_options), MP_ROM_PTR(&curl_Options_obj) }, - { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&curl_GET_obj) }, - { MP_ROM_QSTR(MP_QSTR_post), MP_ROM_PTR(&curl_POST_obj) }, - { MP_ROM_QSTR(MP_QSTR_sendmail), MP_ROM_PTR(&curl_sendmail_obj) }, + { MP_ROM_QSTR(MP_QSTR_info), MP_ROM_PTR(&curl_info_obj) }, + { MP_ROM_QSTR(MP_QSTR_options), MP_ROM_PTR(&curl_Options_obj) }, + { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&curl_GET_obj) }, + { MP_ROM_QSTR(MP_QSTR_post), MP_ROM_PTR(&curl_POST_obj) }, + { MP_ROM_QSTR(MP_QSTR_sendmail), MP_ROM_PTR(&curl_sendmail_obj) }, #ifdef CONFIG_MICROPY_USE_CURLFTP - { MP_ROM_QSTR(MP_QSTR_ftp_get), MP_ROM_PTR(&curl_FTP_GET_obj) }, - { MP_ROM_QSTR(MP_QSTR_ftp_put), MP_ROM_PTR(&curl_FTP_PUT_obj) }, - { MP_ROM_QSTR(MP_QSTR_ftp_list), MP_ROM_PTR(&curl_FTP_LIST_obj) }, + { MP_ROM_QSTR(MP_QSTR_ftp_get), MP_ROM_PTR(&curl_FTP_GET_obj) }, + { MP_ROM_QSTR(MP_QSTR_ftp_put), MP_ROM_PTR(&curl_FTP_PUT_obj) }, + { MP_ROM_QSTR(MP_QSTR_ftp_list), MP_ROM_PTR(&curl_FTP_LIST_obj) }, #endif - { MP_ROM_QSTR(MP_QSTR_SMTP), MP_ROM_INT(QUICKMAIL_PROT_SMTP) }, - { MP_ROM_QSTR(MP_QSTR_SMTPS), MP_ROM_INT(QUICKMAIL_PROT_SMTPS) }, + // Constants + { MP_ROM_QSTR(MP_QSTR_SMTP), MP_ROM_INT(QUICKMAIL_PROT_SMTP) }, + { MP_ROM_QSTR(MP_QSTR_SMTPS), MP_ROM_INT(QUICKMAIL_PROT_SMTPS) }, }; STATIC MP_DEFINE_CONST_DICT(curl_module_globals, curl_module_globals_table); diff --git a/MicroPython_BUILD/components/micropython/esp32/modssh.c b/MicroPython_BUILD/components/micropython/esp32/modssh.c index 6921e2a..0eaf939 100644 --- a/MicroPython_BUILD/components/micropython/esp32/modssh.c +++ b/MicroPython_BUILD/components/micropython/esp32/modssh.c @@ -49,41 +49,40 @@ #include "extmod/vfs_native.h" #include "libssh2.h" + //------------------------------------------------------------------------------------------------------- STATIC mp_obj_t curl_SSH_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, uint8_t type) { checkConnection(); - enum { ARG_url, ARG_user, ARG_pass, ARG_file, ARG_port }; + enum { ARG_url, ARG_user, ARG_pass, ARG_key, ARG_file, ARG_port }; const mp_arg_t allowed_args[] = { { MP_QSTR_url, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } }, { MP_QSTR_user, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } }, { MP_QSTR_password, MP_ARG_REQUIRED | MP_ARG_OBJ, { .u_obj = mp_const_none } }, - { MP_QSTR_file, MP_ARG_OBJ, { .u_obj = mp_const_none } }, - { MP_QSTR_port, MP_ARG_INT, { .u_int = 22 } }, + { MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, { .u_obj = mp_const_none } }, + { MP_QSTR_file, MP_ARG_KW_ONLY | MP_ARG_OBJ, { .u_obj = mp_const_none } }, + { MP_QSTR_port, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = 22 } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); int res; - int hdr_len = hdr_maxlen; - int body_len = body_maxlen; + int hdr_len = ssh2_hdr_maxlen; + int body_len = ssh2_body_maxlen; vstr_t header; vstr_t body; char *url = NULL; char *user = NULL; char *pass = NULL; char *fname = NULL; + char *key = NULL; char server[128] = {'\0'}; char fullname[128] = {'\0'}; + char fullkey[128] = {'\0'}; char scppath[128] = {'\0'}; - /*uint8_t type = (uint8_t)args[ARG_type].u_int; - if (type > 4) { - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Unsupported operation type")); - }*/ - uint16_t port = (uint16_t)args[ARG_port].u_int; char sport[8] = {'\0'}; sprintf(sport,"%u", port); @@ -104,7 +103,18 @@ STATIC mp_obj_t curl_SSH_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_ } user = (char *)mp_obj_str_get_str(args[ARG_user].u_obj); - pass = (char *)mp_obj_str_get_str(args[ARG_pass].u_obj); + + if (MP_OBJ_IS_STR(args[ARG_key].u_obj)) { + // Authenticate using a key pair + key = (char *)mp_obj_str_get_str(args[ARG_key].u_obj); + res = physicalPath(key, fullkey); + if ((res != 0) || (strlen(fullkey) == 0)) { + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Error resolving key file name")); + } + key = fullkey; + if (args[ARG_pass].u_obj != mp_const_none) pass = (char *)mp_obj_str_get_str(args[ARG_pass].u_obj); + } + else pass = (char *)mp_obj_str_get_str(args[ARG_pass].u_obj); if ((type == 0) || (type == 1)) { if (MP_OBJ_IS_STR(args[ARG_file].u_obj)) { @@ -115,7 +125,7 @@ STATIC mp_obj_t curl_SSH_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_ nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Error resolving file name")); } fname = fullname; - body_len = MIN_HDR_BODY_BUF_LEN; + body_len = MIN_BODY_BUF_LEN; } else if (type == 1) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Expected file name for upload")); @@ -128,7 +138,7 @@ STATIC mp_obj_t curl_SSH_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_ body.buf[0] = '\0'; MP_THREAD_GIL_EXIT(); - res = ssh_SCP(type, server, sport, scppath, user, pass, fname, header.buf, body.buf, hdr_len, body_len); + res = ssh_SCP(type, server, sport, scppath, user, pass, key, fname, header.buf, body.buf, hdr_len, body_len); MP_THREAD_GIL_ENTER(); mp_obj_t tuple[3]; @@ -183,25 +193,90 @@ STATIC mp_obj_t SSH2_exec(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_ } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(SSH2_exec_obj, 3, SSH2_exec); +//-------------------------------------------------------------------------------------- +STATIC mp_obj_t SSH2_Options(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) +{ + enum { ARG_print, ARG_verbose, ARG_progress, ARG_timeout, ARG_maxfsize, ARG_hdrlen, ARG_bodylen, ARG_trace }; + const mp_arg_t allowed_args[] = { + { MP_QSTR_print, MP_ARG_BOOL, { .u_bool = true } }, + { MP_QSTR_verbose, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + { MP_QSTR_progress, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + { MP_QSTR_maxfsize, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + { MP_QSTR_hdrlen, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + { MP_QSTR_bodylen, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + { MP_QSTR_trace, MP_ARG_KW_ONLY | MP_ARG_INT, { .u_int = -1 } }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (args[ARG_verbose].u_int >= 0) ssh2_verbose = args[ARG_verbose].u_int & 1; + if (args[ARG_progress].u_int >= 0) ssh2_progress = args[ARG_progress].u_int; + if (args[ARG_timeout].u_int >= 10) ssh2_session_timeout = args[ARG_timeout].u_int; + if (args[ARG_maxfsize].u_int > 1000) ssh2_maxbytes = args[ARG_maxfsize].u_int; + if (args[ARG_hdrlen].u_int > MIN_HDR_BUF_LEN) ssh2_hdr_maxlen = args[ARG_hdrlen].u_int; + if (args[ARG_bodylen].u_int > MIN_BODY_BUF_LEN) ssh2_body_maxlen = args[ARG_bodylen].u_int; + if (args[ARG_trace].u_int >= 0) ssh2_session_trace = args[ARG_trace].u_int & 0x3FF; + + if (ssh2_session_timeout > CONFIG_TASK_WDT_TIMEOUT_S) ssh2_session_timeout = CONFIG_TASK_WDT_TIMEOUT_S - 2; + if (ssh2_session_timeout < 2) ssh2_session_timeout = 2; + if (ssh2_session_timeout > 30) ssh2_session_timeout = 30; + + if (args[ARG_print].u_bool) { + mp_printf(&mp_plat_print, "SSH options(\n Verbose: %s, Progress: %d, Timeout: %d s, Max fsize: %d, Header len: %d, Body len: %d, Trace: %s (0x%03X)\n)\n", + ((ssh2_verbose) ? "True" : "False"), ssh2_progress, ssh2_session_timeout, ssh2_maxbytes, ssh2_hdr_maxlen, ssh2_body_maxlen, ((ssh2_session_trace) ? "True" : "False"), ssh2_session_trace); + + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(SSH2_Options_obj, 0, SSH2_Options); -//============================================================ -STATIC const mp_rom_map_elem_t curl_module_globals_table[] = { +/* + * Trace constants + LIBSSH2_TRACE_TRANS (1<<1) + LIBSSH2_TRACE_KEX (1<<2) + LIBSSH2_TRACE_AUTH (1<<3) + LIBSSH2_TRACE_CONN (1<<4) + LIBSSH2_TRACE_SCP (1<<5) + LIBSSH2_TRACE_SFTP (1<<6) + LIBSSH2_TRACE_ERROR (1<<7) + LIBSSH2_TRACE_PUBLICKEY (1<<8) + LIBSSH2_TRACE_SOCKET (1<<9) +*/ + +//=========================================================== +STATIC const mp_rom_map_elem_t ssh_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ssh) }, - { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&SSH2_GET_obj) }, - { MP_ROM_QSTR(MP_QSTR_put), MP_ROM_PTR(&SSH2_PUT_obj) }, - { MP_ROM_QSTR(MP_QSTR_list), MP_ROM_PTR(&SSH2_LIST_obj) }, - { MP_ROM_QSTR(MP_QSTR_llist), MP_ROM_PTR(&SSH2_LLIST_obj) }, - { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&SSH2_mkdir_obj) }, - { MP_ROM_QSTR(MP_QSTR_exec), MP_ROM_PTR(&SSH2_exec_obj) }, + { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&SSH2_GET_obj) }, + { MP_ROM_QSTR(MP_QSTR_put), MP_ROM_PTR(&SSH2_PUT_obj) }, + { MP_ROM_QSTR(MP_QSTR_list), MP_ROM_PTR(&SSH2_LIST_obj) }, + { MP_ROM_QSTR(MP_QSTR_llist), MP_ROM_PTR(&SSH2_LLIST_obj) }, + { MP_ROM_QSTR(MP_QSTR_mkdir), MP_ROM_PTR(&SSH2_mkdir_obj) }, + { MP_ROM_QSTR(MP_QSTR_exec), MP_ROM_PTR(&SSH2_exec_obj) }, + { MP_ROM_QSTR(MP_QSTR_options), MP_ROM_PTR(&SSH2_Options_obj) }, + + // Constants + { MP_ROM_QSTR(MP_QSTR_TRACE_TRANS), MP_ROM_INT(LIBSSH2_TRACE_TRANS) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_KEX), MP_ROM_INT(LIBSSH2_TRACE_KEX) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_AUTH), MP_ROM_INT(LIBSSH2_TRACE_AUTH) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_CONN), MP_ROM_INT(LIBSSH2_TRACE_CONN) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_SCP), MP_ROM_INT(LIBSSH2_TRACE_SCP) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_SFTP), MP_ROM_INT(LIBSSH2_TRACE_SFTP) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_ERROR), MP_ROM_INT(LIBSSH2_TRACE_ERROR) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_PUBLICKEY), MP_ROM_INT(LIBSSH2_TRACE_PUBLICKEY) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_SOCKET), MP_ROM_INT(LIBSSH2_TRACE_SOCKET) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_NONE), MP_ROM_INT(0) }, + { MP_ROM_QSTR(MP_QSTR_TRACE_ALL), MP_ROM_INT(0x3FE) }, }; -STATIC MP_DEFINE_CONST_DICT(curl_module_globals, curl_module_globals_table); +STATIC MP_DEFINE_CONST_DICT(ssh_module_globals, ssh_module_globals_table); //====================================== const mp_obj_module_t mp_module_ssh = { .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&curl_module_globals, + .globals = (mp_obj_dict_t*)&ssh_module_globals, }; #endif diff --git a/MicroPython_BUILD/components/micropython/esp32/mpconfigport.h b/MicroPython_BUILD/components/micropython/esp32/mpconfigport.h index 5cfb9d6..fe35ccb 100644 --- a/MicroPython_BUILD/components/micropython/esp32/mpconfigport.h +++ b/MicroPython_BUILD/components/micropython/esp32/mpconfigport.h @@ -230,7 +230,7 @@ extern const struct _mp_obj_module_t mp_module_curl; #ifdef CONFIG_MICROPY_USE_SSH extern const struct _mp_obj_module_t mp_module_ssh; -#define BUILTIN_MODULE_SSH { MP_OBJ_NEW_QSTR(MP_QSTR_curl), (mp_obj_t)&mp_module_ssh }, +#define BUILTIN_MODULE_SSH { MP_OBJ_NEW_QSTR(MP_QSTR_ssh), (mp_obj_t)&mp_module_ssh }, #else #define BUILTIN_MODULE_SSH #endif diff --git a/MicroPython_BUILD/components/micropython/esp32/mpversion.h b/MicroPython_BUILD/components/micropython/esp32/mpversion.h index 3f52b74..be62379 100644 --- a/MicroPython_BUILD/components/micropython/esp32/mpversion.h +++ b/MicroPython_BUILD/components/micropython/esp32/mpversion.h @@ -1,8 +1,8 @@ // MicroPython version info -#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.8" +#define MICROPY_GIT_TAG "ESP32_LoBo_v3.1.9" #define MICROPY_GIT_HASH "g2ddee729" -#define MICROPY_BUILD_DATE "2017-01-19" +#define MICROPY_BUILD_DATE "2017-01-21" #define MICROPY_VERSION_MAJOR (3) #define MICROPY_VERSION_MINOR (1) -#define MICROPY_VERSION_MICRO (8) -#define MICROPY_VERSION_STRING "3.1.8" +#define MICROPY_VERSION_MICRO (9) +#define MICROPY_VERSION_STRING "3.1.9" diff --git a/MicroPython_BUILD/components/micropython/py/builtinhelp.c b/MicroPython_BUILD/components/micropython/py/builtinhelp.c index c999290..f5d3583 100644 --- a/MicroPython_BUILD/components/micropython/py/builtinhelp.c +++ b/MicroPython_BUILD/components/micropython/py/builtinhelp.c @@ -33,9 +33,9 @@ #if MICROPY_PY_BUILTINS_HELP const char mp_help_default_text[] = -"Welcome to MicroPython!\n" +"Welcome to LoBo MicroPython\n" "\n" -"For online docs please visit http://docs.micropython.org/\n" +"For online documentation please visit\nhttps://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki\n" "\n" "Control commands:\n" " CTRL-A -- on a blank line, enter raw REPL mode\n" diff --git a/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip b/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip index 23f401c..e4d8477 100644 Binary files a/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip and b/MicroPython_BUILD/firmware/MicroPython_LoBo_Firmwares.zip differ diff --git a/MicroPython_BUILD/firmware/esp32/MicroPython.bin b/MicroPython_BUILD/firmware/esp32/MicroPython.bin index 791381d..4ddeab5 100644 Binary files a/MicroPython_BUILD/firmware/esp32/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin index 7024f4a..1a4205d 100644 Binary files a/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin index 72412a4..cc85ee6 100644 Binary files a/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_ota/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin index 8d1754a..3a16485 100644 Binary files a/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_ota/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin index 24e5f61..acc11fa 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin index 17c7ff9..2cca925 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin index c4ed0d8..0ce5f7c 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram_all/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin index 9e8aec9..b679cfa 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram_all/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin index 4db1551..976f348 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram_ota/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin b/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin index 9c70c09..d9b44cb 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin and b/MicroPython_BUILD/firmware/esp32_psram_ota/bootloader/bootloader.bin differ diff --git a/MicroPython_BUILD/sdkconfig.defaults b/MicroPython_BUILD/sdkconfig.defaults index 3410c52..d7871b6 100644 --- a/MicroPython_BUILD/sdkconfig.defaults +++ b/MicroPython_BUILD/sdkconfig.defaults @@ -13,6 +13,17 @@ CONFIG_ESPTOOLPY_FLASHFREQ_40M=y CONFIG_ESPTOOLPY_FLASHFREQ="40m" CONFIG_FLASHMODE_DIO=y +# +# Bootloader config +# +CONFIG_LOG_BOOTLOADER_LEVEL_NONE= +CONFIG_LOG_BOOTLOADER_LEVEL_ERROR= +CONFIG_LOG_BOOTLOADER_LEVEL_WARN=y +CONFIG_LOG_BOOTLOADER_LEVEL_INFO= +CONFIG_LOG_BOOTLOADER_LEVEL_DEBUG= +CONFIG_LOG_BOOTLOADER_LEVEL_VERBOSE= +CONFIG_LOG_BOOTLOADER_LEVEL=2 + # # ESP32 specific # @@ -24,8 +35,17 @@ CONFIG_ESP32_PANIC_PRINT_HALT=y CONFIG_ESP32_PHY_INIT_DATA_IN_PARTITION=y CONFIG_TASK_WDT_TIMEOUT_S=15 -CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y -CONFIG_LOG_DEFAULT_LEVEL=4 +# +# Log output +# +CONFIG_LOG_DEFAULT_LEVEL_NONE= +CONFIG_LOG_DEFAULT_LEVEL_ERROR= +CONFIG_LOG_DEFAULT_LEVEL_WARN=y +CONFIG_LOG_DEFAULT_LEVEL_INFO= +CONFIG_LOG_DEFAULT_LEVEL_DEBUG= +CONFIG_LOG_DEFAULT_LEVEL_VERBOSE= +CONFIG_LOG_DEFAULT_LEVEL=2 +CONFIG_LOG_COLORS=y # # FreeRTOS