diag: trace RTC synchronization and WSS clock state
This commit is contained in:
@@ -82,6 +82,7 @@ SRC_FILES+= \
|
||||
DP1312EA.c \
|
||||
mqtt.c \
|
||||
mqtt_connect_diag.c \
|
||||
time_diag.c \
|
||||
vad_det.c \
|
||||
sleep_wake.c \
|
||||
battery.c \
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "hal_api.h"
|
||||
#include "nfc.h"
|
||||
#include "ota_baseline.h"
|
||||
#include "time_diag.h"
|
||||
|
||||
|
||||
#define APP_ENABLE_SLEEP
|
||||
@@ -147,6 +148,7 @@ static void custom_app_task(void * argv)
|
||||
|
||||
hal_os_get_build_time(tempbuf);
|
||||
printf("BUILD TIME:%s\r\n",tempbuf);
|
||||
talkingq_time_diag_boot();
|
||||
printf("[OTA-BASELINE] layout=%s profile=%s app_phys=0x%08lX app_xip=0x%08lX app_size=%lu fs_size=%lu slot=single\r\n",
|
||||
BANBAN_OTA_LAYOUT_ID,
|
||||
BANBAN_OTA_BUILD_PROFILE,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef TALKINGQ_APP_TIME_DIAG_H
|
||||
#define TALKINGQ_APP_TIME_DIAG_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
void talkingq_time_diag_boot(void);
|
||||
/* Raw kernel snapshot only: safe to call before the application's first RTC read. */
|
||||
void talkingq_time_diag_log(const char *phase);
|
||||
/* Returns the original time(NULL) sample for the existing WSS threshold check. */
|
||||
time_t talkingq_time_diag_wss_time(void);
|
||||
|
||||
#endif
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "sockets.h"
|
||||
#include "ql_rtos.h"
|
||||
#include <time.h>
|
||||
#include "time_diag.h"
|
||||
#include "rws_handshake.h"
|
||||
#ifdef LIBRWS_USING_MBED_TLS
|
||||
#include "mbedtls/base64.h"
|
||||
@@ -1945,7 +1946,8 @@ int rws_ssl_conn(_rws_socket *s)
|
||||
LOG_E("WSS requires a trusted root CA\n");
|
||||
goto exit;
|
||||
}
|
||||
if (time(NULL) < 1704067200) {
|
||||
stage = "check RTC time";
|
||||
if (talkingq_time_diag_wss_time() < 1704067200) {
|
||||
LOG_E("WSS requires valid network/RTC time before certificate verification\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "ql_atcmd.h"
|
||||
#include "http_downfile.h"
|
||||
#include "ota_post_update.h"
|
||||
#include "time_diag.h"
|
||||
|
||||
//#define NTP_SERVER_DOMAIN "ntp.aliyun.com"
|
||||
|
||||
@@ -141,6 +142,7 @@ void ql_datacall_demo_thread(void *arvg)
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
talkingq_time_diag_log("pdp-active");
|
||||
ql_get_data_call_info(1, 0, &info);
|
||||
printf("info.profile_idx: %d\r\n", info.profile_idx);
|
||||
printf("info.ip_version: %d\r\n", info.ip_version);
|
||||
@@ -197,6 +199,8 @@ int app_net_mgt_init()
|
||||
// ql_rtos_semaphore_create(&g_ql_ntp_sem,0);
|
||||
|
||||
ql_rtc_set_nitz_mode(1);
|
||||
printf("[TIME-DIAG] nitz_enabled=1 app_ntp_enabled=0\r\n");
|
||||
talkingq_time_diag_log("nitz-enabled");
|
||||
|
||||
ql_task_t appTaskRef = NULL;
|
||||
ql_rtos_task_create(&appTaskRef, 1024*4, 100, "app_net_mgt", ql_datacall_demo_thread, NULL);
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "ql_func.h"
|
||||
#include "ql_rtc.h"
|
||||
#include "ql_rtos.h"
|
||||
#include "ql_dev.h"
|
||||
#include "build_macro.h"
|
||||
#include "time_diag.h"
|
||||
#include "../../../../ql-config/config/talkingq_time_diag.h"
|
||||
|
||||
void talkingq_time_diag_log(const char *phase)
|
||||
{
|
||||
talkingq_time_diag_snapshot_fn snapshot;
|
||||
talkingq_time_diag_snapshot s;
|
||||
int ret;
|
||||
|
||||
snapshot = m_get_api_ptr ? (talkingq_time_diag_snapshot_fn)
|
||||
m_get_api_ptr(TALKINGQ_TIME_DIAG_API_NAME) : NULL;
|
||||
if (!snapshot) {
|
||||
printf("[TIME-DIAG] phase=%s ticks=%lu kernel_diag=unavailable "
|
||||
"need_matching_diagnostic_kernel=1\r\n", phase,
|
||||
(unsigned long)ql_rtos_get_systicks());
|
||||
return;
|
||||
}
|
||||
memset(&s, 0, sizeof(s));
|
||||
ret = snapshot(&s, sizeof(s));
|
||||
if (ret != 0 || s.abi_version != TALKINGQ_TIME_DIAG_ABI_VERSION) {
|
||||
printf("[TIME-DIAG] phase=%s kernel_diag=abi_mismatch rc=%d abi=%u\r\n",
|
||||
phase, ret, s.abi_version);
|
||||
return;
|
||||
}
|
||||
printf("[TIME-DIAG] phase=%s ticks=%u abi=%u rtc_init=%u "
|
||||
"counter=%lu sys_offset=%lu app_offset=%lu "
|
||||
"sys_raw=%lu app_raw=%lu follows_sys=%u app_ever=%u storage=%d\r\n",
|
||||
phase, s.sample_ticks, s.abi_version, s.rtc_initialized,
|
||||
(unsigned long)s.counter, (unsigned long)s.sys_offset,
|
||||
(unsigned long)s.app_offset,
|
||||
(unsigned long)(s.counter + s.sys_offset),
|
||||
(unsigned long)(s.counter + s.app_offset),
|
||||
s.app_follows_sys, s.app_ever_configured, s.offset_storage);
|
||||
printf("[TIME-DIAG] phase=%s ticks=%u net_tz_min=%d rtc_tz_hour=%d source=%d "
|
||||
"ntp_type=%d ntp_status=%d ntp_ready=%d gnss_rtc=%d cid=%d "
|
||||
"triggers=%d dns_attempted=%d ntp_ip=%.31s\r\n",
|
||||
phase, s.sample_ticks, s.network_tz_minutes, s.rtc_tz_hours, s.rtc_source,
|
||||
s.ntp_type, s.ntp_status, s.ntp_ready, s.gnss_rtc_status, s.gnss_cid,
|
||||
s.ntp_triggers, s.ntp_dns_attempted, s.ntp_server);
|
||||
}
|
||||
|
||||
void talkingq_time_diag_boot(void)
|
||||
{
|
||||
char firmware[128] = {0};
|
||||
int ret = ql_dev_get_firmware_version(firmware, sizeof(firmware));
|
||||
firmware[sizeof(firmware) - 1] = '\0';
|
||||
printf("[TIME-DIAG] boot app_ver=%s app_build=%s app_rev=%s "
|
||||
"diag_build=%s %s firmware_rc=%d firmware=%s\r\n",
|
||||
CUSTOM_APP_BUILD_VER, CUSTOM_APP_BUILD_TIME, CUSTOM_APP_BUILD_REV,
|
||||
__DATE__, __TIME__, ret, firmware);
|
||||
talkingq_time_diag_log("boot-before-nitz");
|
||||
}
|
||||
|
||||
time_t talkingq_time_diag_wss_time(void)
|
||||
{
|
||||
time_t original;
|
||||
time_t with_pointer;
|
||||
time_t pointer_value = 1;
|
||||
ql_rtc_time_t rtc;
|
||||
int rtc_ret;
|
||||
|
||||
/* Capture raw flags first. Do not replace or correct the existing gate. */
|
||||
talkingq_time_diag_log("wss-before-time-read");
|
||||
original = time(NULL);
|
||||
with_pointer = time(&pointer_value);
|
||||
memset(&rtc, 0, sizeof(rtc));
|
||||
rtc_ret = ql_rtc_get_time(&rtc);
|
||||
printf("[TIME-DIAG] phase=wss-precheck ticks=%lu time_null=%ld "
|
||||
"time_ptr_return=%ld time_ptr_value=%ld rtc_rc=%d "
|
||||
"app_calendar=%04d-%02d-%02dT%02d:%02d:%02d min_epoch=1704067200 valid=%d\r\n",
|
||||
(unsigned long)ql_rtos_get_systicks(), (long)original,
|
||||
(long)with_pointer, (long)pointer_value, rtc_ret,
|
||||
rtc.tm_year, rtc.tm_mon, rtc.tm_mday, rtc.tm_hour, rtc.tm_min, rtc.tm_sec,
|
||||
original >= 1704067200);
|
||||
talkingq_time_diag_log("wss-after-time-read");
|
||||
return original;
|
||||
}
|
||||
Reference in New Issue
Block a user