debug: 在 json_process_frame + handle_pwd_verify 增加详细日志

添加关键路径诊断日志以定位鉴权失败根因:
- json_process_frame: msg_id/cmd/匹配结果/auth状态
- handle_pwd_verify: data提取/password值/dev_pwd对照
This commit is contained in:
wangfq
2026-06-30 19:03:00 +08:00
parent 6389271bfc
commit 3e00a352d3

View File

@@ -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);
}
}