From 3e00a352d31ee55c242ca0e860fb6487643acef7 Mon Sep 17 00:00:00 2001 From: wangfq Date: Tue, 30 Jun 2026 19:03:00 +0800 Subject: [PATCH] =?UTF-8?q?debug:=20=E5=9C=A8=20json=5Fprocess=5Fframe=20+?= =?UTF-8?q?=20handle=5Fpwd=5Fverify=20=E5=A2=9E=E5=8A=A0=E8=AF=A6=E7=BB=86?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加关键路径诊断日志以定位鉴权失败根因: - json_process_frame: msg_id/cmd/匹配结果/auth状态 - handle_pwd_verify: data提取/password值/dev_pwd对照 --- .../OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c index 0264b58..0e5e09d 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c @@ -159,16 +159,24 @@ static int json_extract_frame(uint8_t *buf, uint16_t *len, char *frame_out, uint /* 4.1 pwd_verify */ static void handle_pwd_verify(uint8_t socket, uint32_t msg_id, const char *json) { + PRINT("JSON: pwd_verify handler entered\n"); char *data = json_get_data_str(json); if (!data) { + PRINT("JSON: pwd_verify — data is NULL\n"); json_send_error(socket, msg_id, "pwd_verify", JSON_CODE_PARAM_ERR, "missing data"); return; } + PRINT("JSON: pwd_verify — data=[%s]\n", data); char password[16] = {0}; json_get_str_field(data, "\"password\"", password, sizeof(password)); free(data); + PRINT("JSON: pwd_verify — password=[%s] len=%d\n", password, strlen(password)); + PRINT("JSON: pwd_verify — dev_pwd=[%c%c%c%c%c%c]\n", + g_dev_password[0], g_dev_password[1], g_dev_password[2], + g_dev_password[3], g_dev_password[4], g_dev_password[5]); + if (strlen(password) == 0) { json_send_error(socket, msg_id, "pwd_verify", JSON_CODE_PARAM_ERR, "missing password"); return; @@ -551,7 +559,10 @@ static void json_process_frame(uint8_t socket, const char *frame) { char cmd[32] = {0}; json_get_cmd(frame, cmd, sizeof(cmd)); + PRINT("JSON dispatch: msg_id=%lu cmd=[%s] len=%d\n", msg_id, cmd, strlen(cmd)); + if (strlen(cmd) == 0) { + PRINT("JSON: empty cmd, sending error\n"); json_send_error(socket, msg_id, "", JSON_CODE_PARAM_ERR, "missing cmd field"); return; } @@ -560,12 +571,15 @@ static void json_process_frame(uint8_t socket, const char *frame) { int handled = 0; for (int i = 0; i < JSON_CMD_COUNT; i++) { if (strcmp(cmd, g_cmd_table[i].cmd) == 0) { + PRINT("JSON: matched cmd[%d]=%s, need_auth=%d, auth_state=%d\n", + i, g_cmd_table[i].cmd, g_cmd_table[i].need_auth, g_json_auth_state); // Check auth if (g_cmd_table[i].need_auth && g_json_auth_state != JSON_STATE_AUTHED) { json_send_error(socket, msg_id, cmd, JSON_CODE_NOT_AUTHED, "not authenticated"); handled = 1; break; } + PRINT("JSON: calling handler for %s\n", cmd); g_cmd_table[i].handler(socket, msg_id, frame); handled = 1; break; @@ -574,7 +588,7 @@ static void json_process_frame(uint8_t socket, const char *frame) { if (!handled) { json_send_error(socket, msg_id, cmd, JSON_CODE_UNSUPPORTED, "unsupported command"); - PRINT("JSON: unsupported cmd: %s\n", cmd); + PRINT("JSON: unsupported cmd: [%s]\n", cmd); } }