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