1、lwip 添加 sntp,smtp,mbedtls 编译选项
authorSnickerSun <snickersun@163.com>
Mon, 3 Jun 2024 15:02:46 +0000 (23:02 +0800)
committerSnickerSun <snickersun@163.com>
Mon, 3 Jun 2024 15:02:46 +0000 (23:02 +0800)
2、取消cat1 gettime 指令, 改用 sntp标准网络方案同步时间
3、bleEvent里 采用和sntp相同的设置指令设置时间
4、custom_utils_at_cmd 修改ota_download为 https方案,暂时未调通。

15 files changed:
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c
code/sdk/drivers/peripheral/config/include/ConfigModel.h
code/sdk/drivers/peripheral/config/include/ConfigModelC.h
code/sdk/drivers/peripheral/config/src/ConfigModel.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server.cpp
code/sdk/drivers/peripheral/utils/custom_runtime.c
code/sdk/drivers/peripheral/utils/custom_runtime.h
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h
code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c
code/sdk/open_source/openharmony/third_party/lwip/CMakeLists.txt
code/sdk/open_source/openharmony/third_party/lwip/port/lwip-2.1/porting/include/lwip/lwipopts.h
code/sdk/open_source/openharmony/third_party/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c
code/sdk/open_source/openharmony/third_party/lwip/src/apps/sntp/sntp.c
code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/sntp.h

index 81d6daa..d9deb4e 100644 (file)
@@ -1207,8 +1207,8 @@ void senfindphoneSend(uint8_t flag)
 \r
 static uint8_t jsonCheck_time(uint8_t *buf)//json 格式解析\r
 {\r
-    char time_data[24];\r
-    memset(time_data,0,24);\r
+    // char time_data[24];\r
+    // memset(time_data,0,24);\r
     \r
     uint8_t *json;\r
     json = buf;\r
@@ -1225,9 +1225,11 @@ static uint8_t jsonCheck_time(uint8_t *buf)//json 格式解析
     uint8_t hour = 0;\r
     uint8_t minute = 0;\r
     uint8_t second = 0;\r
+    uint32_t timestamp;\r
     cJSON* time = cJSON_GetObjectItem(root, "time");\r
     if (cJSON_IsNumber(time)) {\r
         printf("time: %d\n", time->valueint);\r
+        timestamp = time->valueint;\r
         // printf("time: %d\n", time->valueint);\r
     }\r
     cJSON* jsweek = cJSON_GetObjectItem(root, "week");\r
@@ -1270,8 +1272,10 @@ static uint8_t jsonCheck_time(uint8_t *buf)//json 格式解析
         printf("location: %s\n", location->valuestring);\r
         locations = location->valuestring;\r
     }\r
-    sprintf((char *)time_data,"%d-%d-%d %d:%d:%d",year+2000,month,day,hour,minute,second);\r
-    set_system_time(time_data);\r
+    // sprintf((char *)time_data,"%d-%d-%d %d:%d:%d",year+2000,month,day,hour,minute,second);\r
+    // set_system_time(time_data);\r
+    uaip_sntp_set_time_utc(timestamp);\r
+\r
     cJSON_Delete(root);\r
     return 1;\r
 }\r
index b907575..e88fdaa 100644 (file)
@@ -43,6 +43,7 @@ namespace OHOS
             CONFIGMODEL_ITEM_CAT1_PYVER,                        //Cat1 Python app version
             CONFIGMODEL_ITEM_LANGUAGE_ID,                       //语言ID    int id
             CONFIGMODEL_ITEM_LANGUAGE_CODE,                       //语言Code string "zh","en"
+            CONFIGMODEL_ITEM_TIMEZONE,                          //单位分钟  默认+8 小时 = 15*4*8 = 480 分钟
             CONFIGMODEL_ITEM_SILENT_MODE,                       //静音模式模式
             CONFIGMODEL_ITEM_VIBRATOR_SWITCH,                   // 马达 开关,0 强,1 中,2 弱,3 关
             CONFIGMODEL_ITEM_RAISE_TO_WAKE,                 //抬腕亮屏开关
@@ -227,6 +228,7 @@ namespace OHOS
             {ConfigDataType::DATATYPE_STRING,  "Cat1_PYVer",               ""      },//CONFIGMODEL_ITEM_CAT1_PYVER,
             {ConfigDataType::DATATYPE_INT,     "LanguageID",               "-1"    },//CONFIGMODEL_ITEM_LANGUAGE_ID, //默认没有选择语言
             {ConfigDataType::DATATYPE_STRING,  "LanguageCode",             ""      },//CONFIGMODEL_ITEM_LANGUAGE_CODE, //默认没有选择语言
+            {ConfigDataType::DATATYPE_INT,     "TimeZone",                 "480"      },//CONFIGMODEL_ITEM_TIMEZONE, //单位分钟  默认+8 小时 = 15*4*8 = 480 分钟
             {ConfigDataType::DATATYPE_BOOL,    "SlientMode",               "false" },//CONFIGMODEL_ITEM_SILENT_MODE,
             {ConfigDataType::DATATYPE_INT,     "VibratorSwitch",           "1"     },//CONFIGMODEL_ITEM_VIBRATOR_SWITCH, // 马达 开关,0 强,1 中,2 弱,3 关
             {ConfigDataType::DATATYPE_BOOL,    "Rase2Wake",                "true"  },//CONFIGMODEL_ITEM_RAISE_TO_WAKE,
index caa10bd..5a90c08 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-17 09:32:03
- * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-24 11:44:39
+ * @LastEditors: SnickerSun snickersun@163.com
+ * @LastEditTime: 2024-06-03 16:39:34
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModelC.h
  */
 #ifndef _CONFIG_MODEL_C_H_
@@ -81,6 +81,11 @@ bool get_HFP_switch(void);
 
 bool get_A2DP_switch(void);
 
+
+void set_timezone_minutes(int16_t timezone_minutes);
+
+int16_t get_timezone_minutes(void);
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index 1e4ec44..4c7fd2c 100644 (file)
@@ -1,6 +1,7 @@
 #include "ConfigModel.h"
 #include "ConfigModelC.h"
 #include "custom_utils.h"
+#include "custom_runtime.h"
 namespace OHOS
 {
     ConfigModel::ConfigModel()
@@ -881,9 +882,17 @@ extern "C" {
 #endif
 #endif
 
+/*开机时从配置文件里读取的文件,直接同步到runtime里,方便其他应用使用*/
+void installize_dev_runtime(void)
+{
+    int16_t timezone = get_timezone_minutes();
+    uapi_dev_runtime_set_timezone_minutes(timezone);
+}
+    
 uint32_t ConfigModelInit(void)
 {
     OHOS::ConfigModel::GetInstance()->Init();
+    installize_dev_runtime();
     return 0;
 }
 
@@ -998,6 +1007,18 @@ bool get_A2DP_switch(void)
     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getA2DPSwitch %d",isopen);
     return isopen;
 }
+void set_timezone_minutes(int16_t timezone_minutes)
+{
+    OHOS::ConfigModel::GetInstance()->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TIMEZONE,timezone_minutes);
+}
+
+int16_t get_timezone_minutes(void)
+{
+    int16_t timezone_minutes;
+    timezone_minutes = OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_TIMEZONE);
+    return timezone_minutes;
+}
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index f9491bb..8343481 100644 (file)
@@ -30,6 +30,7 @@
 #include "wearable_log.h"
 #include "custom_runtime.h"
 
+#include "lwip/apps/sntp.h"
 // #include "graphic_service.h"
 
 #ifdef __cplusplus
@@ -832,7 +833,7 @@ void restart_sleep_cat1_timer(void)
 static void time_sync_func(void)
 {
     
-    PRINT("time_sync_func\n");
+    // PRINT("time_sync_func\n");
 
     runtime_status_t * runtime = get_device_runtime_status();
     if (uapi_cat1_get_power_stat() == false )
@@ -849,7 +850,8 @@ static void time_sync_func(void)
          runtime->cat1_runtime.cat1_powerOn = 1;
 
     }
-    cat1_getsignal();
+
+#if USE_CAT1_CMD_SYNC_TIME
     
     if(osTimerIsRunning(g_timer_time_sync)==1 && g_time_synced == 1 )
     {
@@ -868,7 +870,14 @@ static void time_sync_func(void)
         return ;
     }
     cat1_gettime();
+#endif
 
+    if (uapi_get_screen_state() == 1)
+    {
+         cat1_getsignal();
+    }else{
+        // printf("Screen off skip get signal\n");
+    }
 }
 
 void restart_time_sync(void)
@@ -1049,6 +1058,13 @@ static int udp_packet_parse(char *rx_buffer, int len)
                     get_sim_iccid_toCat1();
                     get_regist_time_toCat1();
                 #endif
+                if(sntp_enabled()==0)
+                {
+                    sntp_init();
+                }else{
+                    sntp_stop();
+                    sntp_init();
+                }
             }
             break;
         case UDP_MSG_GET_TELECON_DMP_TIMESEC:
@@ -1141,7 +1157,7 @@ void cat1_server_task(void *pvParameters)
 
         while (1) {
 
-            printf("recv ENTER\r\n");
+            // printf("recv ENTER\r\n");
             
                        memset(rx_buffer, 0, sizeof(rx_buffer));
             int len = recvfrom(g_listen_sock, rx_buffer, sizeof(rx_buffer) - 1, 0, (struct sockaddr *)&sourceAddr, &addrLen);
index 10453a0..f9fb399 100644 (file)
@@ -45,12 +45,28 @@ uint8_t uapi_dev_runtime_get_earphone_connect_stat(void)
 
 
 
-uint8_t uapi_dev_runtime_set_android_connection_status(uint8_t is_android)
+void uapi_dev_runtime_set_android_connection_status(uint8_t is_android)
 {
-    g_runtime.android_app_connected = is_android;
-    return is_android;
+    g_runtime.android_app_connected = is_android;    
 }
 uint8_t uapi_dev_runtime_get_android_connection_status(void)
 {
     return g_runtime.android_app_connected;
+}
+
+void uapi_dev_runtime_set_timezone_minutes(int16_t timezone_minutes)
+{
+    g_runtime.timezone_minutes = timezone_minutes;   
+}
+
+int16_t uapi_dev_runtime_get_timezone_minutes(void)
+{
+    return g_runtime.timezone_minutes;
+}
+
+//关机前,把runtime数据同步到config文件里
+void uapi_dev_runtime_sync_runtime_env_to_config(void)
+{
+    set_timezone_minutes(g_runtime.timezone_minutes);
+
 }
\ No newline at end of file
index e915795..1732901 100644 (file)
@@ -78,7 +78,7 @@ typedef struct
     uint8_t android_app_connected;
     cat1_runtime_status_t cat1_runtime;
     uint8_t current_dial_name[32];
-
+    int16_t timezone_minutes;
 } runtime_status_t;
 
 /**
@@ -126,12 +126,20 @@ uint8_t uapi_dev_runtime_get_earphone_connect_stat(void);
 /**
  * 设置 android app connect status
 */
-uint8_t uapi_dev_runtime_set_android_connection_status(uint8_t is_android);
+void uapi_dev_runtime_set_android_connection_status(uint8_t is_android);
 /**
  * 获取 android app connect status
 */
 uint8_t uapi_dev_runtime_get_android_connection_status(void);
 
+
+void uapi_dev_runtime_set_timezone_minutes(int16_t timezone_minutes);
+
+int16_t uapi_dev_runtime_get_timezone_minutes(void);
+
+
+void uapi_dev_runtime_sync_runtime_env_to_config(void);
+
 #ifdef __cplusplus
 #if __cplusplus
 }
index f16c08c..f3266e2 100644 (file)
@@ -148,6 +148,9 @@ void shutdown_reboot_prejobs_task(void)
     addressbookTowrite();
     
     uapi_calendar_store_date();
+    //同步所有需要保存实时数据到config文件
+    uapi_dev_runtime_sync_runtime_env_to_config();
+    //保存config文件到磁盘
     sync_all_config_to_disk();
 }
 static bool doing_shutdown_or_reboot = false;
@@ -403,6 +406,80 @@ errcode_t uapi_get_timestampe_ss(uint32_t *tm)
     return ERRCODE_SUCC;
 }
 
+errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_minutes)
+{
+    struct timeval tv = { 0 };
+    struct timezone tz = { 0 };
+
+    tv.tv_sec = seconds;
+    tv.tv_usec = 0;
+    tz.tz_dsttime = 0;
+    tz.tz_minuteswest = zone_minutes;
+    uapi_dev_runtime_set_timezone_minutes(zone_minutes);
+    return settimeofday(&tv, &tz);
+}
+
+errcode_t uaip_sntp_set_time_utc(uint32_t seconds)
+{
+
+
+    int zone_minutes = uapi_dev_runtime_get_timezone_minutes();
+   
+    uaip_set_time_utc_zone(seconds,zone_minutes);
+
+    time_t rawtime;
+    struct tm timeinfo;
+    time(&rawtime);
+    localtime_r(&rawtime,&timeinfo);
+
+    printf("uaip_sntp_set_time_utc set time success %04d-%02d-%02d %02d:%02d:%02d %d\n",
+    timeinfo.tm_year + 1900,
+    timeinfo.tm_mon + 1,
+    timeinfo.tm_mday,
+    timeinfo.tm_hour,
+    timeinfo.tm_min,
+    timeinfo.tm_sec,zone_minutes);
+    
+     return ERRCODE_SUCC;
+}
+/*已经包含timezone时间,*/
+errcode_t uaip_set_time_local(uint32_t seconds)
+{
+     int zone_minutes = uapi_dev_runtime_get_timezone_minutes();
+
+    uaip_set_time_utc_zone((seconds-(zone_minutes*60)),zone_minutes);
+
+    time_t rawtime;
+    struct tm timeinfo;
+    time(&rawtime);
+    localtime_r(&rawtime,&timeinfo);
+
+    printf("uaip_set_time_local set time success %04d-%02d-%02d %02d:%02d:%02d %d\n",
+    timeinfo.tm_year + 1900,
+    timeinfo.tm_mon + 1,
+    timeinfo.tm_mday,
+    timeinfo.tm_hour,
+    timeinfo.tm_min,
+    timeinfo.tm_sec,zone_minutes);
+    
+    return ERRCODE_SUCC;
+
+}
+
+errcode_t uaip_set_time_local_full(uint32_t year,uint32_t month, uint32_t day, uint32_t hour,uint32_t minutes,uint32_t seconds)
+{
+    uint32_t allseconds=0;
+    struct tm tm = { 0 };
+    tm.tm_yday = year - 1900;
+    tm.tm_mon = month - 1;
+    tm.tm_mday = day;
+    tm.tm_hour = hour;
+    tm.tm_min = minutes;
+    tm.tm_sec = seconds;
+    allseconds = (uint32_t)__tm_to_secs(&tm);
+    return uaip_set_time_local(allseconds);
+}
+
 #define BITS_PER_BYTE               8
 #define HEXADECIMAL                 16
 #define DECIMAL                     10
@@ -818,11 +895,18 @@ void uapi_setScreenDuration(int32_t time)
 
 /*
  * @brief 获取屏幕状态 
+ * return 1 screen on  ,  0 screen off
 */
 int32_t uapi_get_screen_state(void)
 {
     const power_display_svr_api_t *display_api = power_display_svr_get_api();
-    return display_api->get_screen_state();
+    screen_state_t state = display_api->get_screen_state();
+    // printf("uapi_get_screen_state = %s . \r\n", state==SCREEN_ON?"on":"off");
+    if( state == SCREEN_ON){
+        return 1;
+    }else{
+        return 0;
+    }
 }
 
 /**
@@ -1333,7 +1417,7 @@ void touch_getstate(void)
 {
     int32_t state;
     state = uapi_get_screen_state();
-    PRINT("state : %d\r\n",state);
+    PRINT("Screen On state : %d\r\n",state);
 }
 
 #include "MMC5603.h"
index 2098b2f..c657778 100644 (file)
@@ -41,7 +41,19 @@ errcode_t uaip_cmd_update_request(void);
 errcode_t uapi_get_timestampe_ms(uint32_t *tm);
 /*获取单位秒的时间戳*/
 errcode_t uapi_get_timestampe_ss(uint32_t *tm);
-/**根据cat1获取的时间字串设置时间*/
+
+/**设置utc时间+timezone*/
+errcode_t uaip_set_time_utc_zone(uint32_t seconds,int16_t zone_minutes);
+
+/*sntp同步UTC 时间 , 采用默认timezone,或者已经保存detimezone*/
+errcode_t uaip_sntp_set_time_utc(uint32_t seconds);
+
+/*已经包含timezone时间,*/
+errcode_t uaip_set_time_local(uint32_t seconds);
+/*已经包含timezone时间,*/
+errcode_t uaip_set_time_local_full(uint32_t year,uint32_t month, uint32_t day, uint32_t hour,uint32_t minutes,uint32_t seconds);
+
+/**根据cat1获取的时间字串设置时间 */
 errcode_t uapi_set_time_from_cat1(char* cat1time);
 
 /**获取日期*/
@@ -63,7 +75,10 @@ void ScreenAlwaysOnCtr(uint8_t turnOnFlag);
 void uapi_setScreenBrightness(int value);
 
 void uapi_setScreenDuration(int32_t time);
-
+/*
+ * @brief 获取屏幕状态 
+ * return 1 screen on  ,  0 screen off
+*/
 int32_t uapi_get_screen_state(void);
 
 void uapi_systemVolumeSet(int16_t sounding);
index 069aa70..2faf474 100644 (file)
@@ -7,6 +7,8 @@
 #include "custom_utils.h"
 #include "debug_print.h"
 
+#include "lwip/altcp_tls.h"
+
 #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
 #define CUSTOM_UTILS_MAX_ARGC            8
 #define CUSTOM_UTILS_MAX_ARGV_LEN        256
@@ -110,6 +112,44 @@ err_t httpc_download_file_recv_ui(httpc_state_t *connection, u32_t rx_len,u32_t
     PRINT("httpc_download_file_recv_ui recv %d bytes total received %d filelen %d\r\n",rx_len,rx_total_len,file_total_len);
     return 0;
 }
+
+// SSL CA PEMs  
+/* AWS */
+/* AZURE */
+const char SSL_CA_PEM[] = "-----BEGIN CERTIFICATE-----\n"
+"MIICrDCCAlKgAwIBAgIJAJo+BOgbcQBUMAoGCCqGSM49BAMDMIGwMQswCQYDVQQG\n"
+"EwJVUzEOMAwGA1UECAwFVGV4YXMxDzANBgNVBAcMBkF1c3RpbjEQMA4GA1UECgwH\n"
+"T1NJc29mdDEQMA4GA1UECwwHT1NJc29mdDE5MDcGA1UEAwwwZWMyLTE4LTEzMC03\n"
+"OC01MC5ldS13ZXN0LTIuY29tcHV0ZS5hbWF6b25hd3MuY29tMSEwHwYJKoZIhvcN\n"
+"AQkBFhJkbG9wZXpAb3Npc29mdC5jb20wHhcNMTgwNjIwMjA1ODA3WhcNMjgwNjE3\n"
+"MjA1ODA3WjCBsDELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVRleGFzMQ8wDQYDVQQH\n"
+"DAZBdXN0aW4xEDAOBgNVBAoMB09TSXNvZnQxEDAOBgNVBAsMB09TSXNvZnQxOTA3\n"
+"BgNVBAMMMGVjMi0xOC0xMzAtNzgtNTAuZXUtd2VzdC0yLmNvbXB1dGUuYW1hem9u\n"
+"YXdzLmNvbTEhMB8GCSqGSIb3DQEJARYSZGxvcGV6QG9zaXNvZnQuY29tMFkwEwYH\n"
+"KoZIzj0CAQYIKoZIzj0DAQcDQgAEe4ufVcWu5MwkbE4d6iF1cOhQpgmamQF61RNl\n"
+"KiDCfN2jZxR6WYTMHE1UECwZKB7Vj4cMczEgecGAjjjk/Nqnr6NTMFEwHQYDVR0O\n"
+"BBYEFE8wR6UrcQxeUTVayZNRUZVIX9ViMB8GA1UdIwQYMBaAFE8wR6UrcQxeUTVa\n"
+"yZNRUZVIX9ViMA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwMDSAAwRQIgfS68\n"
+"tBUHIJxatGCbZS2vVvCXSR2ojHMkkrxVOfoBCMwCIQDAk7ODHjFev0hX1eoHjtky\n"
+"e0wjSDehvRytFUNZ9yqwag==\n"
+"-----END CERTIFICATE-----\n"
+"-----BEGIN CERTIFICATE-----\n"
+"MIICQzCCAegCCQCTvXzEGfGkljAKBggqhkjOPQQDAzCBqDELMAkGA1UEBhMCVVMx\n"
+"CzAJBgNVBAgMAlRYMQ8wDQYDVQQHDAZBdXN0aW4xEDAOBgNVBAoMB09TSXNvZnQx\n"
+"EDAOBgNVBAsMB0hvdXN0b24xNDAyBgNVBAMMK3Bpc3lzdGVtNzQ2NTYud2VzdGV1\n"
+"cm9wZS5jbG91ZGFwcC5henVyZS5jb20xITAfBgkqhkiG9w0BCQEWEmRsb3BlekBv\n"
+"c2lzb2Z0LmNvbTAeFw0xODA1MTYxNDI1MzJaFw0yODA1MTMxNDI1MzJaMIGoMQsw\n"
+"CQYDVQQGEwJVUzELMAkGA1UECAwCVFgxDzANBgNVBAcMBkF1c3RpbjEQMA4GA1UE\n"
+"CgwHT1NJc29mdDEQMA4GA1UECwwHSG91c3RvbjE0MDIGA1UEAwwrcGlzeXN0ZW03\n"
+"NDY1Ni53ZXN0ZXVyb3BlLmNsb3VkYXBwLmF6dXJlLmNvbTEhMB8GCSqGSIb3DQEJ\n"
+"ARYSZGxvcGV6QG9zaXNvZnQuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\n"
+"u67uXtCYyzZe3si9Dv3ai/e5/MuAFQNkjdJCNMDijZFomiCSlm9TETi4zkBG8lxk\n"
+"zT+6OQsmoG/Zbp5ZNNI+4zAKBggqhkjOPQQDAwNJADBGAiEA4NqJMQQFhPFLvWbK\n"
+"H1/egQjtly1ML0G4mCemIQfhSBkCIQCaIBAiTNVefJxL5cEvg1MnNRMfConzRFqD\n"
+"u1PsWfdL5A==\n"
+"-----END CERTIFICATE-----\n";
+
+altcp_allocator_t *g_allocator = NULL;
 static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
 {
     UNUSED(strCommonCmd);
@@ -136,9 +176,23 @@ static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char
     uint8_t *otadatapath = (uint8_t*)argv[3];
     PRINT("custom_start_ota_download %s:%d %s to %s\r\n",server,port,uri,otadatapath);
     httpc_connection_t settings = {0};
+    size_t calen = sizeof(SSL_CA_PEM);
+    struct altcp_tls_config *tlsconfig = altcp_tls_create_config_client((const uint8_t *)SSL_CA_PEM,calen);
+    PRINT("custom_start_ota_download pa perm %s  \n======len %d \r\n",SSL_CA_PEM,calen);
+
+
+    g_allocator = malloc(sizeof(altcp_allocator_t));
+    if (g_allocator==NULL) return ERRCODE_MALLOC;
+    g_allocator->alloc = altcp_tls_alloc;
+    g_allocator->arg = (void*)tlsconfig;
+
+
+
+    settings.altcp_allocator=g_allocator;
     settings.result_fn=httpc_download_result;
     settings.file_rx_fn = httpc_download_file_recv_ui;
     settings.headers_done_fn=httpc_download_headers_done;
+
     settings.use_post = 0 ;
 
     httpc_state_t* connection=NULL;
@@ -481,6 +535,22 @@ static uint32_t custom_utils_pdudec(uint8_t *para, uint32_t paraLen, char *strCo
     return ERRCODE_SUCC;
 }
 
+#include "lwip/apps/sntp.h"
+static uint32_t custom_test_sntp(uint8_t *para, uint32_t paraLen, char *strCommonCmd)
+{
+    UNUSED(strCommonCmd);
+    
+    if(sntp_enabled()==0)
+    {
+        sntp_init();
+    }else{
+        sntp_stop();
+        sntp_init();
+    }
+    PRINT("CUSTOM_UTILSTEST ATCMD custom_test_sntp sntp_init \n");
+    return ERRCODE_SUCC;
+}
+
 static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CUSTOM_SN",      custom_utils_setsn, (char *)"123456789ABCDEF2345678" },
     { (char *)"AT^CUSTOM_SN_REQ",  custom_utils_getsn, (char *)" " },
@@ -490,7 +560,7 @@ static const at_cmd_table_t g_custom_utils_cmd[] = {
 
     { (char *)"AT^TOUCHID",      custom_touch_getid, (char *)" " },
 
-    { (char *)"AT^TOUCHSTATE",      custom_touch_getstate, (char *)" " },
+    { (char *)"AT^SCREENSTATE",      custom_touch_getstate, (char *)" " },
 
     { (char *)"AT^MMC5603ID",      custom_mmc5603_getid, (char *)" " },
 
@@ -525,6 +595,9 @@ static const at_cmd_table_t g_custom_utils_cmd[] = {
     { (char *)"AT^CYWEEGETSLEEPDATA",      custom_cywee_get_sleep_data, (char *)" " },
     { (char *)"AT^LZMADEC",      custom_utils_lzmadec, (char *)" " },
     { (char *)"AT^PDUDEC",      custom_utils_pdudec, (char *)" " },
+    { (char *)"AT^SNTP",      custom_test_sntp, (char *)" " },
+
+    
 
 };
 
index 86f1273..7972cee 100644 (file)
@@ -69,11 +69,12 @@ set(SOURCES
     ${lwipapi_SRCS}
     ${lwipnetif_SRCS}
     ${lwipcore6_SRCS}
+    ${lwipport_SRCS}
+    ${lwiptest_SRCS}
     ${lwipsntp_SRCS}
     ${lwipmbedtls_SRCS}
+    ${lwipsmtp_SRCS}
     ${lwiphttp_SRCS}
-    ${lwipport_SRCS}
-    ${lwiptest_SRCS}
 )
 
 set(PUBLIC_HEADER
index a17cb10..414886b 100644 (file)
 #define _LWIP_PORTING_LWIPOPTS_H_
 
 // lwIP debug options, comment the ones you don't want
-#define LWIP_DEBUG 0
+#define LWIP_DEBUG 1
 #if LWIP_DEBUG
 #define ETHARP_DEBUG                    LWIP_DBG_OFF
-#define NETIF_DEBUG                     LWIP_DBG_ON
+#define NETIF_DEBUG                     LWIP_DBG_OFF
 #define PBUF_DEBUG                      LWIP_DBG_OFF
 #define API_LIB_DEBUG                   LWIP_DBG_OFF
 #define API_MSG_DEBUG                   LWIP_DBG_OFF
-#define SOCKETS_DEBUG                   LWIP_DBG_ON
+#define SOCKETS_DEBUG                   LWIP_DBG_OFF
 #define ICMP_DEBUG                      LWIP_DBG_OFF
 #define IGMP_DEBUG                      LWIP_DBG_OFF
 #define INET_DEBUG                      LWIP_DBG_OFF
-#define IP_DEBUG                        LWIP_DBG_ON
-#define DRIVERIF_DEBUG                  LWIP_DBG_ON
-#define IP_REASS_DEBUG                  LWIP_DBG_ON
-#define RAW_DEBUG                       LWIP_DBG_ON
-#define MEM_DEBUG                       LWIP_DBG_ON
-#define MEMP_DEBUG                      LWIP_DBG_ON
-#define SYS_DEBUG                       LWIP_DBG_ON
+#define IP_DEBUG                        LWIP_DBG_OFF
+#define DRIVERIF_DEBUG                  LWIP_DBG_OFF
+#define IP_REASS_DEBUG                  LWIP_DBG_OFF
+#define RAW_DEBUG                       LWIP_DBG_OFF
+#define MEM_DEBUG                       LWIP_DBG_OFF
+#define MEMP_DEBUG                      LWIP_DBG_OFF
+#define SYS_DEBUG                       LWIP_DBG_OFF
 #define TIMERS_DEBUG                    LWIP_DBG_OFF
-#define TCP_DEBUG                       LWIP_DBG_ON
-#define TCP_ERR_DEBUG                   LWIP_DBG_ON
-#define TCP_INPUT_DEBUG                 LWIP_DBG_ON
+#define TCP_DEBUG                       LWIP_DBG_OFF
+#define TCP_ERR_DEBUG                   LWIP_DBG_OFF
+#define TCP_INPUT_DEBUG                 LWIP_DBG_OFF
 #define TCP_FR_DEBUG                    LWIP_DBG_OFF
 #define TCP_RTO_DEBUG                   LWIP_DBG_OFF
 #define TCP_CWND_DEBUG                  LWIP_DBG_OFF
 #define TCP_WND_DEBUG                   LWIP_DBG_OFF
-#define TCP_OUTPUT_DEBUG                LWIP_DBG_ON
+#define TCP_OUTPUT_DEBUG                LWIP_DBG_OFF
 #define TCP_RST_DEBUG                   LWIP_DBG_OFF
 #define TCP_QLEN_DEBUG                  LWIP_DBG_OFF
 #define TCP_SACK_DEBUG                  LWIP_DBG_OFF
 #define TCP_TLP_DEBUG                   LWIP_DBG_OFF
-#define UDP_DEBUG                       LWIP_DBG_ON
-#define TCPIP_DEBUG                     LWIP_DBG_ON
-#define SLIP_DEBUG                      LWIP_DBG_ON
+#define UDP_DEBUG                       LWIP_DBG_OFF
+#define TCPIP_DEBUG                     LWIP_DBG_OFF
+#define SLIP_DEBUG                      LWIP_DBG_OFF
 #define DHCP_DEBUG                      LWIP_DBG_OFF
 #define AUTOIP_DEBUG                    LWIP_DBG_OFF
-#define DNS_DEBUG                       LWIP_DBG_ON
+#define DNS_DEBUG                       LWIP_DBG_OFF
 #define TFTP_DEBUG                      LWIP_DBG_OFF
-#define SYS_ARCH_DEBUG                  LWIP_DBG_ON
-#define SNTP_DEBUG                      LWIP_DBG_OFF
+#define SYS_ARCH_DEBUG                  LWIP_DBG_OFF
+#define SNTP_DEBUG                      LWIP_DBG_ON
 #define IP6_DEBUG                       LWIP_DBG_OFF
 #define DHCP6_DEBUG                     LWIP_DBG_OFF
 #define DRV_STS_DEBUG                   LWIP_DBG_OFF
+#define HTTPC_DEBUG                     LWIP_DBG_ON
+
+#define ALTCP_MBEDTLS_MEM_DEBUG         LWIP_DBG_ON
+#define ALTCP_MBEDTLS_DEBUG             LWIP_DBG_ON
+#define ALTCP_MBEDTLS_LIB_DEBUG         LWIP_DBG_ON
 #endif
 
+
+
 // Options only in new opt.h
 #define LWIP_SOCKET_SELECT              0
 #define LWIP_SOCKET_POLL                1
 
 #define LWIP_ALTCP                      1
 #define LWIP_ALTCP_TLS                  1
+#define LWIP_ALTCP_TLS_MBEDTLS          1
+
 
 #if defined LWIP_STATS_DISPLAY && !LWIP_STATS
 #undef LWIP_STATS_DISPLAY
 #define LWIP_SOCKET_FCNTL               0
 
 #define LWIP_HTTPC_HAVE_FILE_IO         1
+#define HTTPC_DEBUG_REQUEST             1
+
+#define LWIP_DHCP_MAX_NTP_SERVERS       3
+#define SNTP_SERVER_DNS                 1
+#if SNTP_SERVER_DNS
+#define SNTP_SERVER_ADDRESS "cn.pool.ntp.org" //"pool.ntp.org"
+#define SNTP_SERVER_ADDRESS2 "ntp1.aliyun.com" //"pool.ntp.org"
+#define SNTP_SERVER_ADDRESS3 "pool.ntp.org" //"pool.ntp.org"
+#endif
+
+#define SNTP_SET_SYSTEM_TIME(sec)   uaip_sntp_set_time_utc(sec)
 
 #endif /* _LWIP_PORTING_LWIPOPTS_H_ */
index bb8e623..47d5d22 100644 (file)
 
 #include "altcp_tls_mbedtls_structs.h"
 #include "altcp_tls_mbedtls_mem.h"
+#if (MBEDTLS_VERSION_NUMBER == 0x03010000)
+#include "mbedtls/pk.h"
+#include "mbedtls/net_sockets.h"
+#include "mbedtls/x509_crt.h"
 
+#else
+#include "mbedtls/certs.h"
+#include "mbedtls/x509.h"
+#include "mbedtls/net.h"
+#include "mbedtls/ssl_internal.h" /* to call mbedtls_flush_output after ERR_MEM */
+#endif
 /* @todo: which includes are really needed? */
 #include "mbedtls/entropy.h"
 #include "mbedtls/ctr_drbg.h"
-#include "mbedtls/certs.h"
-#include "mbedtls/x509.h"
 #include "mbedtls/ssl.h"
-#include "mbedtls/net.h"
 #include "mbedtls/error.h"
 #include "mbedtls/debug.h"
 #include "mbedtls/platform.h"
@@ -78,7 +85,6 @@
 #include "mbedtls/ssl_cache.h"
 #include "mbedtls/ssl_ticket.h"
 
-#include "mbedtls/ssl_internal.h" /* to call mbedtls_flush_output after ERR_MEM */
 
 #include <string.h>
 
@@ -675,7 +681,7 @@ altcp_tls_create_config(int is_server, uint8_t cert_count, uint8_t pkey_count, i
   struct altcp_tls_config *conf;
   mbedtls_x509_crt *mem;
 
-  if (TCP_WND < MBEDTLS_SSL_MAX_CONTENT_LEN) {
+  if (TCP_WND < MBEDTLS_SSL_IN_CONTENT_LEN) {
     LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG|LWIP_DBG_LEVEL_SERIOUS,
       ("altcp_tls: TCP_WND is smaller than the RX decrypion buffer, connection RX might stall!\n"));
   }
@@ -825,7 +831,7 @@ err_t altcp_tls_config_server_add_privkey_cert(struct altcp_tls_config *config,
     return ERR_VAL;
   }
 
-  ret = mbedtls_pk_parse_key(pkey, (const unsigned char *) privkey, privkey_len, privkey_pass, privkey_pass_len);
+  ret = mbedtls_pk_parse_key(pkey, (const unsigned char *) privkey, privkey_len, privkey_pass, privkey_pass_len,NULL,NULL);
   if (ret != 0) {
     LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_pk_parse_public_key failed: %d\n", ret));
     mbedtls_x509_crt_free(srvcert);
@@ -928,7 +934,7 @@ altcp_tls_create_config_client_2wayauth(const u8_t *ca, size_t ca_len, const u8_
   }
 
   mbedtls_pk_init(conf->pkey);
-  ret = mbedtls_pk_parse_key(conf->pkey, privkey, privkey_len, privkey_pass, privkey_pass_len);
+  ret = mbedtls_pk_parse_key(conf->pkey, privkey, privkey_len, privkey_pass, privkey_pass_len,NULL,NULL);
   if (ret != 0) {
     LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_pk_parse_key failed: %d 0x%x", ret, -1*ret));
     altcp_mbedtls_free_config(conf);
@@ -1097,7 +1103,11 @@ altcp_mbedtls_sndbuf(struct altcp_pcb *conn)
           size_t ret;
 #if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
           /* @todo: adjust ssl_added to real value related to negociated cipher */
+          #if (MBEDTLS_VERSION_NUMBER == 0x03010000)
+          size_t max_frag_len = mbedtls_ssl_get_max_out_record_payload(&state->ssl_context);
+          #else
           size_t max_frag_len = mbedtls_ssl_get_max_frag_len(&state->ssl_context);
+          #endif
           max_len = LWIP_MIN(max_frag_len, max_len);
 #endif
           /* Adjust sndbuf of inner_conn with what added by SSL */
@@ -1140,12 +1150,19 @@ altcp_mbedtls_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t
   /* HACK: if thre is something left to send, try to flush it and only
      allow sending more if this succeeded (this is a hack because neither
      returning 0 nor MBEDTLS_ERR_SSL_WANT_WRITE worked for me) */
+  #if (MBEDTLS_VERSION_NUMBER == 0x03010000)
+    if(mbedtls_ssl_flush_output(&state->ssl_context) !=0)
+    {
+      return ERR_MEM;
+    }
+  #else
   if (state->ssl_context.out_left) {
     mbedtls_ssl_flush_output(&state->ssl_context);
     if (state->ssl_context.out_left) {
       return ERR_MEM;
     }
   }
+  #endif
   ret = mbedtls_ssl_write(&state->ssl_context, (const unsigned char *)dataptr, len);
   /* try to send data... */
   altcp_output(conn->inner_conn);
index 23731e5..3e4ede5 100644 (file)
@@ -649,8 +649,14 @@ sntp_request(void *arg)
  * @ingroup sntp
  * Initialize this module.
  * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC).
+ * 1、cn.ntp.org.cn:服务器地址为202.114.10.51,由中国科学院国家授时中心提供;
+ * 2、ntp.aliyun.com:由阿里云提供的SNTP服务器,位于杭州,提供多个服务器地址;
+ * 3、ntp2.sysu.edu.cn:由中山大学提供的SNTP服务器,位于广州。
+ * 1、ntp.pool.org:由多个机构提供的NTP服务器集群,可提供全球覆盖的时间同步服务;
+ * 2、ntp1.aliyun.com:由阿里云提供的公共时间服务器池之一,提供高可用的时间同步服务;
+ * 3、cn.pool.ntp.org:中国境内的公共时间服务器池,由多个机构维护。  
  */
-void
+void 
 sntp_init(void)
 {
   /* LWIP_ASSERT_CORE_LOCKED(); is checked by udp_new() */
@@ -664,6 +670,25 @@ sntp_init(void)
 #endif
 #endif /* SNTP_SERVER_ADDRESS */
 
+
+#ifdef SNTP_SERVER_ADDRESS2
+#if SNTP_SERVER_DNS
+  sntp_setservername(1, SNTP_SERVER_ADDRESS2);
+#else
+#error SNTP_SERVER_ADDRESS2 string not supported SNTP_SERVER_DNS==0
+#endif
+#endif /* SNTP_SERVER_ADDRESS2 */
+
+
+#ifdef SNTP_SERVER_ADDRESS3
+#if SNTP_SERVER_DNS
+  sntp_setservername(2, SNTP_SERVER_ADDRESS3);
+#else
+#error SNTP_SERVER_ADDRESS3 string not supported SNTP_SERVER_DNS==0
+#endif
+#endif /* SNTP_SERVER_ADDRESS3 */
+
+
   if (sntp_pcb == NULL) {
     sntp_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
     LWIP_ASSERT("Failed to allocate udp pcb for sntp client", sntp_pcb != NULL);
@@ -692,6 +717,7 @@ sntp_init(void)
 void
 sntp_stop(void)
 {
+  LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_stop \n"));
   LWIP_ASSERT_CORE_LOCKED();
   if (sntp_pcb != NULL) {
 #if SNTP_MONITOR_SERVER_REACHABILITY
@@ -720,6 +746,8 @@ u8_t sntp_enabled(void)
  * @ingroup sntp
  * Sets the operating mode.
  * @param operating_mode one of the available operating modes
+ * #define SNTP_OPMODE_POLL            0
+ * #define SNTP_OPMODE_LISTENONLY      1
  */
 void
 sntp_setoperatingmode(u8_t operating_mode)
index c415253..c7515d4 100644 (file)
@@ -50,7 +50,16 @@ extern "C" {
 #define SNTP_OPMODE_LISTENONLY      1
 void sntp_setoperatingmode(u8_t operating_mode);
 u8_t sntp_getoperatingmode(void);
-
+/**
+ * sntp Initialize this module.
+ * Send out request instantly or after SNTP_STARTUP_DELAY(_FUNC).
+ * 1、cn.ntp.org.cn:服务器地址为202.114.10.51,由中国科学院国家授时中心提供;
+ * 2、ntp.aliyun.com:由阿里云提供的SNTP服务器,位于杭州,提供多个服务器地址;
+ * 3、ntp2.sysu.edu.cn:由中山大学提供的SNTP服务器,位于广州。
+ * 1、ntp.pool.org:(default) 由多个机构提供的NTP服务器集群,可提供全球覆盖的时间同步服务;
+ * 2、ntp1.aliyun.com:由阿里云提供的公共时间服务器池之一,提供高可用的时间同步服务;
+ * 3、cn.pool.ntp.org:中国境内的公共时间服务器池,由多个机构维护。
+ */
 void sntp_init(void);
 void sntp_stop(void);
 u8_t sntp_enabled(void);