xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 1 | /**
|
| 2 | * @file sc_absvr.c
|
| 3 | * @brief Implementation of sc_absvr.
|
| 4 | *
|
| 5 | * Copyright (C) 2023 Sanechips Technology Co., Ltd.
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 6 | * @author
|
| 7 | *
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify
|
| 9 | * it under the terms of the GNU General Public License version 2 as
|
| 10 | * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
|
| 11 | *
|
| 12 | */
|
| 13 |
|
| 14 |
|
| 15 | /*******************************************************************************
|
| 16 | * Include header files *
|
| 17 | ******************************************************************************/
|
| 18 | #include <stdio.h>
|
| 19 | #include <string.h>
|
| 20 | #include <stdlib.h>
|
| 21 | #include <assert.h>
|
| 22 | #include <syslog.h>
|
| 23 | #include <sys/klog.h>
|
| 24 | #include <sys/msg.h>
|
| 25 | #include <sys/un.h>
|
| 26 | #include <errno.h>
|
| 27 | #include <sys/types.h>
|
| 28 | #include <sys/wait.h>
|
| 29 |
|
| 30 | #include "absvr_msg.h"
|
| 31 | #include "zxic_fota_ab_upgrade.h"
|
| 32 | #include "softap_log.h"
|
| 33 | #include "at_reg.h"
|
| 34 | #include "softap_api.h"
|
| 35 |
|
| 36 |
|
| 37 | /*******************************************************************************
|
| 38 | * Macro definitions *
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 39 | ******************************************************************************/
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 40 | #define MSG_DATABUF_MAX_LEN (128)
|
| 41 |
|
| 42 | #define DEBUG 1
|
| 43 |
|
| 44 | //#define ABSVR_PRINT "SC_AB_SVR"
|
| 45 |
|
| 46 | /*******************************************************************************
|
| 47 | * Type definitions *
|
| 48 | ******************************************************************************/
|
| 49 | typedef struct
|
| 50 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 51 | int result; // 0: ³É¹¦ ·Ç0: ʧ°Ü
|
| 52 | unsigned char dataBuf[MSG_DATABUF_MAX_LEN];
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 53 | } absvr_common_result_t;
|
| 54 |
|
| 55 |
|
| 56 | typedef struct
|
| 57 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 58 | int boot_to_system;
|
| 59 | int reboot_flag;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 60 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 61 | int system;
|
| 62 | int status;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 63 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 64 | int status_for_nv;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 65 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 66 | int sync_status;
|
| 67 |
|
| 68 | char package_path[128];
|
| 69 | int len;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 70 | } absvr_common_req_msg_t;
|
| 71 |
|
| 72 |
|
| 73 | /*******************************************************************************
|
| 74 | * Local variable definitions *
|
| 75 | ******************************************************************************/
|
| 76 |
|
| 77 |
|
| 78 | /*******************************************************************************
|
| 79 | * Global variable definitions *
|
| 80 | ******************************************************************************/
|
| 81 |
|
| 82 |
|
| 83 | /*******************************************************************************
|
| 84 | * Local function declarations *
|
| 85 | ******************************************************************************/
|
| 86 | static void flush_upgrade_status(z_upgrade_status_info_t *p_status);
|
| 87 |
|
| 88 | static int absvr_get_upgrade_type(MSG_BUF *msg);
|
| 89 | static int absvr_verify(MSG_BUF *msg);
|
| 90 | static int absvr_update(MSG_BUF *msg);
|
| 91 | static int absvr_sync(MSG_BUF *msg);
|
| 92 | static int absvr_get_upgrade_status(MSG_BUF *msg);
|
| 93 | static int absvr_get_current_system(MSG_BUF *msg);
|
| 94 | static int absvr_get_boot_to_system(MSG_BUF *msg);
|
| 95 | static int absvr_set_boot_to_system(MSG_BUF *msg);
|
| 96 | static int absvr_get_system_status(MSG_BUF *msg);
|
| 97 | static int absvr_set_system_status(MSG_BUF *msg);
|
| 98 | static int absvr_get_fota_status_for_nv(MSG_BUF *msg);
|
| 99 | static int absvr_set_fota_status_for_nv(MSG_BUF *msg);
|
| 100 | static int absvr_get_sync_status(MSG_BUF *msg);
|
| 101 | static int absvr_set_sync_status(MSG_BUF *msg);
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 102 | static int absvr_config_package_path(MSG_BUF *msg);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 103 |
|
| 104 | static int absvr_msg_proc(MSG_BUF *msg);
|
| 105 |
|
| 106 |
|
| 107 | /*******************************************************************************
|
| 108 | * Local function implementations *
|
| 109 | ******************************************************************************/
|
| 110 | static void flush_upgrade_status(z_upgrade_status_info_t *p_status)
|
| 111 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 112 | absvr_common_result_t absvr_common_result = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 113 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 114 | memcpy(absvr_common_result.dataBuf, p_status, sizeof(z_upgrade_status_info_t));
|
| 115 |
|
| 116 | if (0 != send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_UPDATING_RSP, sizeof(absvr_common_result),
|
| 117 | (unsigned char *)(&absvr_common_result)))
|
| 118 | {
|
| 119 | slog(ABSVR_PRINT, SLOG_ERR, "Err: flush_upgrade_status send_soc_msg fail \n");
|
| 120 | }
|
| 121 |
|
| 122 | return;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 123 | }
|
| 124 |
|
| 125 |
|
| 126 | static int absvr_get_upgrade_type(MSG_BUF *msg)
|
| 127 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 128 | absvr_common_result_t absvr_common_result = {0};
|
| 129 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 130 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 131 | ret = zxic_dual_get_upgrade_type();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 132 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 133 | absvr_common_result.result = ret;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 134 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 135 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_UPGRADE_TYPE_RSP, sizeof(absvr_common_result),
|
| 136 | (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 137 | }
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 138 |
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 139 |
|
| 140 | static int absvr_verify(MSG_BUF *msg)
|
| 141 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 142 | absvr_common_result_t absvr_common_result = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 143 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 144 | absvr_common_result.result = zxic_dual_verify();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 145 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 146 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_VRITFY_RSP, sizeof(absvr_common_result),
|
| 147 | (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 148 | }
|
| 149 |
|
| 150 |
|
| 151 | static int absvr_update(MSG_BUF *msg)
|
| 152 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 153 | absvr_common_result_t absvr_common_result = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 154 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 155 | z_upgrade_status_info_t status = {0};
|
| 156 | z_upgrade_flush_status_t flush_status = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 157 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 158 | flush_status.status = &status;
|
| 159 | flush_status.status_cb = &flush_upgrade_status;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 160 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 161 | absvr_common_result.result = zxic_dual_upgrade(&flush_status);
|
| 162 |
|
| 163 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_UPDATE_RSP, sizeof(absvr_common_result),
|
| 164 | (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 165 | }
|
| 166 |
|
| 167 |
|
| 168 | static int absvr_sync(MSG_BUF *msg)
|
| 169 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 170 | absvr_common_result_t absvr_common_result = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 171 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 172 | absvr_common_result.result = zxic_dual_sync_system();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 173 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 174 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_SYNC_RSP, sizeof(absvr_common_result),
|
| 175 | (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 176 | }
|
| 177 |
|
| 178 |
|
| 179 | static int absvr_get_upgrade_status(MSG_BUF *msg)
|
| 180 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 181 | absvr_common_result_t absvr_common_result = {0};
|
| 182 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 183 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 184 | z_upgrade_status_info_t upgrade_info = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 185 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 186 | ret = zxic_dual_get_upgrade_status(&upgrade_info);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 187 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 188 | absvr_common_result.result = ret;
|
| 189 | memcpy(absvr_common_result.dataBuf, &upgrade_info, sizeof(z_upgrade_status_info_t));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 190 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 191 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_UPGRADE_STATUS_RSP,
|
| 192 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 193 | }
|
| 194 |
|
| 195 |
|
| 196 | static int absvr_get_current_system(MSG_BUF *msg)
|
| 197 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 198 | absvr_common_result_t absvr_common_result = {0};
|
| 199 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 200 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 201 | ret = zxic_dual_get_current_system();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 202 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 203 | absvr_common_result.result = ret;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 204 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 205 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_CURRENT_SYSTEM_RSP,
|
| 206 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 207 | }
|
| 208 |
|
| 209 |
|
| 210 | static int absvr_get_boot_to_system(MSG_BUF *msg)
|
| 211 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 212 | absvr_common_result_t absvr_common_result = {0};
|
| 213 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 214 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 215 | ret = zxic_dual_get_boot_to_system();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 216 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 217 | absvr_common_result.result = ret;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 218 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 219 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_BOOT_TO_SYSTEM_RSP,
|
| 220 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 221 | }
|
| 222 |
|
| 223 |
|
| 224 | static int absvr_set_boot_to_system(MSG_BUF *msg)
|
| 225 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 226 | absvr_common_req_msg_t *common_req_msg = NULL;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 227 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 228 | absvr_common_result_t absvr_common_result = {0};
|
| 229 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 230 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 231 | common_req_msg = (absvr_common_req_msg_t *)(msg->aucDataBuf);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 232 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 233 | ret = zxic_dual_set_boot_to_system(common_req_msg->boot_to_system, common_req_msg->reboot_flag);
|
| 234 |
|
| 235 | absvr_common_result.result = ret;
|
| 236 |
|
| 237 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_SET_BOOT_TO_SYSTEM_RSP,
|
| 238 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 239 | }
|
| 240 |
|
| 241 |
|
| 242 | static int absvr_get_system_status(MSG_BUF *msg)
|
| 243 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 244 | absvr_common_result_t absvr_common_result = {0};
|
| 245 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 246 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 247 | z_upgrade_system_info_t system_info = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 248 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 249 | ret = zxic_dual_get_system_status(&system_info);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 250 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 251 | absvr_common_result.result = ret;
|
| 252 | memcpy(absvr_common_result.dataBuf, &system_info, sizeof(z_upgrade_system_info_t));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 253 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 254 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_SYSTEM_STATUS_RSP,
|
| 255 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 256 | }
|
| 257 |
|
| 258 |
|
| 259 | static int absvr_set_system_status(MSG_BUF *msg)
|
| 260 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 261 | absvr_common_req_msg_t *common_req_msg = NULL;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 262 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 263 | absvr_common_result_t absvr_common_result = {0};
|
| 264 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 265 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 266 | common_req_msg = (absvr_common_req_msg_t *)(msg->aucDataBuf);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 267 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 268 | ret = zxic_dual_set_system_status(common_req_msg->system, common_req_msg->status);
|
| 269 |
|
| 270 | absvr_common_result.result = ret;
|
| 271 |
|
| 272 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_SET_SYSTEM_STATUS_RSP,
|
| 273 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 274 | }
|
| 275 |
|
| 276 |
|
| 277 | static int absvr_get_fota_status_for_nv(MSG_BUF *msg)
|
| 278 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 279 | absvr_common_result_t absvr_common_result = {0};
|
| 280 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 281 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 282 | ret = zxic_dual_get_fota_status_for_nv();
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 283 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 284 | absvr_common_result.result = ret;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 285 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 286 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_FOTA_STATUS_FOR_NV_RSP,
|
| 287 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 288 | }
|
| 289 |
|
| 290 |
|
| 291 | static int absvr_set_fota_status_for_nv(MSG_BUF *msg)
|
| 292 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 293 | absvr_common_req_msg_t *common_req_msg = NULL;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 294 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 295 | absvr_common_result_t absvr_common_result = {0};
|
| 296 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 297 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 298 | common_req_msg = (absvr_common_req_msg_t *)(msg->aucDataBuf);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 299 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 300 | ret = zxic_dual_set_fota_status_for_nv(common_req_msg->status_for_nv);
|
| 301 |
|
| 302 | absvr_common_result.result = ret;
|
| 303 |
|
| 304 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_SET_FOTA_STATUS_FOR_NV_RSP,
|
| 305 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 306 | }
|
| 307 |
|
| 308 |
|
| 309 | static int absvr_get_sync_status(MSG_BUF *msg)
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 310 | {
|
| 311 | absvr_common_result_t absvr_common_result = {0};
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 312 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 313 | zxic_dual_get_sync_status(&(absvr_common_result.result));
|
| 314 |
|
| 315 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_GET_SYNC_STATUS_RSP, sizeof(absvr_common_result),
|
| 316 | (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 317 | }
|
| 318 |
|
| 319 |
|
| 320 | static int absvr_set_sync_status(MSG_BUF *msg)
|
| 321 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 322 | absvr_common_req_msg_t *common_req_msg = NULL;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 323 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 324 | absvr_common_result_t absvr_common_result = {0};
|
| 325 | int ret = -1;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 326 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 327 | common_req_msg = (absvr_common_req_msg_t *)(msg->aucDataBuf);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 328 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 329 | ret = zxic_dual_set_sync_status(common_req_msg->sync_status);
|
| 330 |
|
| 331 | absvr_common_result.result = ret;
|
| 332 |
|
| 333 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_SET_SYNC_STATUS_RSP, sizeof(absvr_common_result),
|
| 334 | (unsigned char *)(&absvr_common_result));
|
| 335 | }
|
| 336 |
|
| 337 |
|
| 338 | static int absvr_config_package_path(MSG_BUF *msg)
|
| 339 | {
|
| 340 | absvr_common_req_msg_t *common_req_msg = NULL;
|
| 341 |
|
| 342 | absvr_common_result_t absvr_common_result = {0};
|
| 343 | int ret = -1;
|
| 344 |
|
| 345 | common_req_msg = (absvr_common_req_msg_t *)(msg->aucDataBuf);
|
| 346 |
|
| 347 | ret = zxic_dual_config_package_path(common_req_msg->package_path, common_req_msg->len);
|
| 348 |
|
| 349 | absvr_common_result.result = ret;
|
| 350 |
|
| 351 | return send_soc_msg(FAR_PS, MODULE_ID_ABCLIENT, (unsigned short)ABSVR_CONFIG_PACKAGE_PATH_RSP,
|
| 352 | sizeof(absvr_common_result), (unsigned char *)(&absvr_common_result));
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 353 | }
|
| 354 |
|
| 355 |
|
| 356 | static int absvr_msg_proc(MSG_BUF *msg)
|
| 357 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 358 | int ret = 0;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 359 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 360 | if ( NULL == msg)
|
| 361 | {
|
| 362 | slog(ABSVR_PRINT, SLOG_ERR, "Err: absvr_msg_proc msg is NULL \n");
|
| 363 | return -1;
|
| 364 | }
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 365 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 366 | slog(ABSVR_PRINT, SLOG_NORMAL, "absvr_msg_proc start process msg [%hu] \n", msg->usMsgCmd);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 367 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 368 | switch (msg->usMsgCmd)
|
| 369 | {
|
| 370 | case ABSVR_GET_UPGRADE_TYPE_REQ:
|
| 371 | ret = absvr_get_upgrade_type(msg);
|
| 372 | break;
|
| 373 | case ABSVR_VRITFY_REQ:
|
| 374 | ret = absvr_verify(msg);
|
| 375 | break;
|
| 376 | case ABSVR_UPDATE_REQ:
|
| 377 | ret = absvr_update(msg);
|
| 378 | break;
|
| 379 | case ABSVR_SYNC_REQ:
|
| 380 | ret = absvr_sync(msg);
|
| 381 | break;
|
| 382 | case ABSVR_GET_UPGRADE_STATUS_REQ:
|
| 383 | ret = absvr_get_upgrade_status(msg);
|
| 384 | break;
|
| 385 | case ABSVR_GET_CURRENT_SYSTEM_REQ:
|
| 386 | ret = absvr_get_current_system(msg);
|
| 387 | break;
|
| 388 | case ABSVR_GET_BOOT_TO_SYSTEM_REQ:
|
| 389 | ret = absvr_get_boot_to_system(msg);
|
| 390 | break;
|
| 391 | case ABSVR_SET_BOOT_TO_SYSTEM_REQ:
|
| 392 | ret = absvr_set_boot_to_system(msg);
|
| 393 | break;
|
| 394 | case ABSVR_GET_SYSTEM_STATUS_REQ:
|
| 395 | ret = absvr_get_system_status(msg);
|
| 396 | break;
|
| 397 | case ABSVR_SET_SYSTEM_STATUS_REQ:
|
| 398 | ret = absvr_set_system_status(msg);
|
| 399 | break;
|
| 400 | case ABSVR_GET_FOTA_STATUS_FOR_NV_REQ:
|
| 401 | ret = absvr_get_fota_status_for_nv(msg);
|
| 402 | break;
|
| 403 | case ABSVR_SET_FOTA_STATUS_FOR_NV_REQ:
|
| 404 | ret = absvr_set_fota_status_for_nv(msg);
|
| 405 | break;
|
| 406 | case ABSVR_GET_SYNC_STATUS_REQ:
|
| 407 | ret = absvr_get_sync_status(msg);
|
| 408 | break;
|
| 409 | case ABSVR_SET_SYNC_STATUS_REQ:
|
| 410 | ret = absvr_set_sync_status(msg);
|
| 411 | break;
|
| 412 | case ABSVR_CONFIG_PACKAGE_PATH_REQ:
|
| 413 | ret = absvr_config_package_path(msg);
|
| 414 | break;
|
| 415 | default:
|
| 416 | slog(ABSVR_PRINT, SLOG_ERR, "Err: absvr_msg_proc unknow usMsgCmd [%hu] \n", msg->usMsgCmd);
|
| 417 | break;
|
| 418 | }
|
| 419 |
|
| 420 | return ret;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 421 | }
|
| 422 |
|
| 423 |
|
| 424 | /*******************************************************************************
|
| 425 | * Global function implementations *
|
| 426 | ******************************************************************************/
|
| 427 |
|
| 428 | int main(void)
|
| 429 | {
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 430 | int iRet = 0;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 431 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 432 | int iMsgHandle = 0;
|
| 433 | MSG_BUF stMsg = {0};
|
| 434 | LONG msgSize = sizeof(MSG_BUF) - sizeof(LONG);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 435 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 436 | /*¸ù¾ÝNV³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿*/
|
| 437 | loglevel_init();
|
| 438 | slog(ABSVR_PRINT, SLOG_NORMAL, "sc_absvr begin ======= build date: %s %s \n", __DATE__, __TIME__);
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 439 |
|
lh | 758261d | 2023-07-13 05:52:04 -0700 | [diff] [blame^] | 440 | iMsgHandle = msgget(MODULE_ID_ABSVR, IPC_CREAT | 0600);
|
| 441 | if (-1 == iMsgHandle)
|
| 442 | {
|
| 443 | slog(ABSVR_PRINT, SLOG_ERR, "Err: can not create msg queue for sc_absvr \n");
|
| 444 | return -1;
|
| 445 | }
|
| 446 |
|
| 447 | for (;;)
|
| 448 | {
|
| 449 | memset(&stMsg, 0, sizeof(stMsg));
|
| 450 | iRet = 0;
|
| 451 | iRet = msgrcv(iMsgHandle, &stMsg, msgSize, 0, 0);
|
| 452 | if (-1 == iRet)
|
| 453 | {
|
| 454 | slog(ABSVR_PRINT, SLOG_ERR, "Err: recv msg fail errno = %d \n", errno);
|
| 455 | continue;
|
| 456 | }
|
| 457 |
|
| 458 | if (0 != absvr_msg_proc(&stMsg))
|
| 459 | {
|
| 460 | slog(ABSVR_PRINT, SLOG_ERR, "Err: absvr_msg_proc src_id[%d] usMsgCmd[%hu] fail \n", stMsg.src_id, stMsg.usMsgCmd);
|
| 461 | }
|
| 462 | }
|
| 463 |
|
| 464 | return 0;
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 465 | }
|
| 466 |
|