lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include "ext_regist.h"
|
| 2 |
|
| 3 | #include "NvParam_drv.h"
|
| 4 | #include "libcpnv.h"
|
| 5 | #define ZOSS_ERROR 0xffffffff
|
| 6 | #define ZOSS_SUCCESS 0x0
|
| 7 |
|
| 8 | /*wdt nv flag*/
|
| 9 | #define WDT_OFF (0x57445446) //ascii:WDTF
|
| 10 | #define WDT_ON (0x5744544F) //ascii:WDTO
|
| 11 |
|
| 12 | #define ZX_WDT_IOC_MAGIC 'W'
|
| 13 |
|
| 14 | /*ioctl cmd usd by device*/
|
| 15 | #define ZX_WDT_SET_INTERNAL _IOW(ZX_WDT_IOC_MAGIC, 1, char *)
|
| 16 | #define ZX_WDT_SET_WAKEUP _IOW(ZX_WDT_IOC_MAGIC, 2, char *)
|
| 17 | #define ZX_WDT_FEED_DOG _IOW(ZX_WDT_IOC_MAGIC, 3, char *)
|
| 18 | #define ZX_WDT_GET_HANDLE_TIMEOUT _IOWR(ZX_WDT_IOC_MAGIC, 4, char *)
|
| 19 | #define ZX_WDT_GET_GLOBAL_CNT _IOWR(ZX_WDT_IOC_MAGIC, 5, char *)
|
| 20 | #define ZX_WDT_GET_AP_TIMEOUT _IOWR(ZX_WDT_IOC_MAGIC, 6, char *)
|
| 21 | #define ZX_WDT_SET_AP_SWITCH _IOWR(ZX_WDT_IOC_MAGIC, 7, char *)
|
| 22 | #define ZX_WDT_SET_NV _IOWR(ZX_WDT_IOC_MAGIC, 8, char *)
|
| 23 | #define ZX_WDT_GET_NV _IOWR(ZX_WDT_IOC_MAGIC, 9, char *)
|
| 24 | #define ZX_WDT_SET_CHECK _IOWR(ZX_WDT_IOC_MAGIC, 10, char *)
|
| 25 |
|
| 26 | #define ZX_SOFT_WDT_DEV "/dev/zx_soft_wdt"
|
| 27 |
|
| 28 |
|
| 29 | extern int zx_wdt_set_nv(BOOL nv_flag);
|
| 30 | extern BOOL zx_wdt_get_wdtnv_for_ctrm(void);
|
| 31 | //static long int wdt_fd;
|
| 32 |
|
| 33 | int wdt_act_func(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 34 | {
|
| 35 | char *at_str = NULL;
|
| 36 | unsigned long retCode = ZOSS_ERROR;
|
| 37 | int nv_value = 0;
|
| 38 | unsigned int wdt_nvdata = 0;
|
| 39 |
|
| 40 | assert(at_paras!=NULL);
|
| 41 | at_str = at_paras;
|
| 42 |
|
| 43 | get_at_cmd_param_int(at_str, &nv_value, &at_str);
|
| 44 | at_print(AT_DEBUG,"wdt_act_func:nv_value == %d\n", nv_value);
|
| 45 |
|
| 46 | if(0 == nv_value )
|
| 47 | {
|
| 48 |
|
| 49 | //ioctl(wdt_fd, ZX_WDT_SET_NV, FALSE);
|
| 50 | wdt_nvdata=WDT_OFF;
|
| 51 | retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
|
| 52 | if(ZOSS_SUCCESS == retCode ){
|
| 53 | retCode= cpnv_NvramFlush();
|
| 54 | }
|
| 55 |
|
| 56 | }
|
| 57 | else if(1 == nv_value )
|
| 58 | {
|
| 59 | //ioctl(wdt_fd, ZX_WDT_SET_NV, TRUE);
|
| 60 | wdt_nvdata=WDT_ON;
|
| 61 | retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
|
| 62 | if(ZOSS_SUCCESS == retCode ){
|
| 63 | retCode= cpnv_NvramFlush();
|
| 64 | }
|
| 65 | }
|
| 66 | else
|
| 67 | {
|
| 68 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 69 | *res_msglen = strlen(*res_msg);
|
| 70 | return AT_END;
|
| 71 | }
|
| 72 |
|
| 73 | if (retCode == ZOSS_SUCCESS)
|
| 74 | {
|
| 75 | *res_msg = at_query_result_build("WDT=",at_str);
|
| 76 | }
|
| 77 | else
|
| 78 | {
|
| 79 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 80 | }
|
| 81 |
|
| 82 | *res_msglen = strlen(*res_msg);
|
| 83 | return AT_END;
|
| 84 | }
|
| 85 |
|
| 86 | int wdt_get_nv_state(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 87 | {
|
| 88 |
|
| 89 | unsigned int wdt_nvdata = 0;
|
| 90 | long retCode = CPNV_ERROR;
|
| 91 |
|
| 92 | //ioctl(wdt_fd, ZX_WDT_GET_NV, &retCode);
|
| 93 |
|
| 94 | retCode =cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(wdtSwitch), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtSwitch));
|
| 95 | if(CPNV_ERROR == retCode) softap_assert("");
|
| 96 | if (WDT_OFF == wdt_nvdata )
|
| 97 | {
|
| 98 | *res_msg = at_query_result_build("WDT","WDT OFF");
|
| 99 |
|
| 100 | } else if(WDT_ON== wdt_nvdata )
|
| 101 | {
|
| 102 | *res_msg = at_query_result_build("WDT","WDT ON");
|
| 103 | }
|
| 104 | else
|
| 105 | {
|
| 106 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 107 | }
|
| 108 |
|
| 109 | *res_msglen = strlen(*res_msg);
|
| 110 | return AT_END;
|
| 111 | }
|
| 112 |
|
| 113 | int wdt_set_nv_priority(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 114 | {
|
| 115 | char *at_str = NULL;
|
| 116 | unsigned long retCode = ZOSS_ERROR;
|
| 117 | int nv_value = 0;
|
| 118 | char strCmd[AT_CMD_MAX] = {0};
|
| 119 |
|
| 120 | assert(at_paras!=NULL);
|
| 121 | at_str = at_paras;
|
| 122 |
|
| 123 | get_at_cmd_param_int(at_str, &nv_value, &at_str);
|
| 124 | at_print(AT_DEBUG,"wdt_set_nv_priority:nv_value == %d\n", nv_value);
|
| 125 |
|
| 126 | if((nv_value > 0)&&(nv_value <= 99))//priority
|
| 127 | {
|
| 128 | retCode = cpnv_NvItemWrite(DRV_SYS_NV_ITEM_ADDR(wdtPriority), (unsigned char *)(&nv_value), DRV_SYS_NV_ITEM_SIZE(wdtPriority));
|
| 129 | if(ZOSS_SUCCESS == retCode ){
|
| 130 | retCode= cpnv_NvramFlush();
|
| 131 | }
|
| 132 | }
|
| 133 | else
|
| 134 | {
|
| 135 | *res_msg = at_err_build(ATERR_PARAM_INVALID);
|
| 136 | *res_msglen = strlen(*res_msg);
|
| 137 | return AT_END;
|
| 138 | }
|
| 139 |
|
| 140 | if (retCode == ZOSS_SUCCESS)
|
| 141 | {
|
| 142 | sprintf(strCmd,"%d", nv_value);
|
| 143 | *res_msg = at_query_result_build("WDTP=",strCmd);
|
| 144 | }
|
| 145 | else
|
| 146 | {
|
| 147 | *res_msg = at_err_build(ATERR_PROC_FAILED);
|
| 148 | }
|
| 149 |
|
| 150 | *res_msglen = strlen(*res_msg);
|
| 151 | return AT_END;
|
| 152 | }
|
| 153 |
|
| 154 | int wdt_get_nv_priority(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 155 | {
|
| 156 | unsigned int wdt_nvdata = 0;
|
| 157 | long retCode = CPNV_ERROR;
|
| 158 | char strCmd[AT_CMD_MAX] = {0};
|
| 159 |
|
| 160 | retCode =cpnv_NvItemRead(DRV_SYS_NV_ITEM_ADDR(wdtPriority), (unsigned char *)(&wdt_nvdata), DRV_SYS_NV_ITEM_SIZE(wdtPriority));
|
| 161 | if(CPNV_ERROR == retCode) softap_assert("");
|
| 162 |
|
| 163 | sprintf(strCmd,"%d", wdt_nvdata);
|
| 164 |
|
| 165 | *res_msg = at_query_result_build("WDTP",strCmd);
|
| 166 | *res_msglen = strlen(*res_msg);
|
| 167 | return AT_END;
|
| 168 | }
|
| 169 |
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 170 |
|
| 171 | /*****************
|
| 172 | *
|
| 173 | *
|
| 174 | */
|
| 175 |
|
| 176 | #define RPMSG_IOC_MAGIC 'R'
|
| 177 |
|
| 178 | /*ioctl cmd usd by device*/
|
| 179 | #define RPMSG_CREATE_CHANNEL _IOW(RPMSG_IOC_MAGIC, 1, char *)
|
| 180 | #define RPMSG_GET_DATASIZE _IOWR(RPMSG_IOC_MAGIC, 2, char *)
|
| 181 | #define RPMSG_SET_INT _IOW(RPMSG_IOC_MAGIC, 3, char *)
|
| 182 | #define RPMSG_SET_INT_FLAG _IOW(RPMSG_IOC_MAGIC, 4, char *)
|
| 183 | #define RPMSG_CLEAR_INT_FLAG _IOW(RPMSG_IOC_MAGIC, 5, char *)
|
| 184 | #define RPMSG_SET_POLL_FLAG _IOW(RPMSG_IOC_MAGIC, 6, char *)
|
| 185 | #define RPMSG_CLEAR_POLL_FLAG _IOW(RPMSG_IOC_MAGIC, 7, char *)
|
| 186 | #define AT_CAP_DEV "/dev/rpmsg2"
|
| 187 |
|
| 188 | static void write_lockfile(char *filepath, char *setbuf)
|
| 189 | {
|
| 190 | int f, len = 0;
|
| 191 | f = open(filepath, O_RDWR);
|
| 192 | if (f == -1) {
|
| 193 | at_print(AT_DEBUG,"write_lockfile OPEN FAIL\n");
|
| 194 | return;
|
| 195 | }
|
| 196 | len = strlen(setbuf);
|
| 197 | if (write(f, setbuf, len) != len)
|
| 198 | { }
|
| 199 | else
|
| 200 | { }
|
| 201 |
|
| 202 | close(f);
|
| 203 | }
|
| 204 |
|
| 205 | static int pm_apadd_wakelock(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 206 | {
|
| 207 | char strCmd[AT_CMD_MAX] = {0};
|
| 208 |
|
| 209 | write_lockfile("/sys/power/wake_lock", "test_wakelock");
|
| 210 |
|
| 211 | *res_msg = at_query_result_build("delete_lock",strCmd);
|
| 212 | *res_msglen = strlen(*res_msg);
|
| 213 | return AT_END;
|
| 214 | }
|
| 215 |
|
| 216 | static int pm_apdelete_wakelock(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 217 | {
|
| 218 | char strCmd[AT_CMD_MAX] = {0};
|
| 219 |
|
| 220 | write_lockfile("/sys/power/wake_unlock", "test_wakelock");
|
| 221 |
|
| 222 | *res_msg = at_query_result_build("delete_lock",strCmd);
|
| 223 | *res_msglen = strlen(*res_msg);
|
| 224 |
|
| 225 | return AT_END;
|
| 226 | }
|
| 227 |
|
| 228 |
|
| 229 | static int pm_capadd_wakelock(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 230 | {
|
| 231 | char strCmd[AT_CMD_MAX] = {0};
|
| 232 | unsigned int ctx=0x5a5a;
|
| 233 | int fd, ret;
|
| 234 |
|
| 235 | at_print(AT_DEBUG,"pm_capadd_wakelock\n");
|
| 236 |
|
| 237 |
|
| 238 | fd =open(AT_CAP_DEV, O_RDWR);
|
| 239 | if(fd<0){
|
| 240 | at_print(AT_DEBUG,"cap add open FAIL\n");
|
| 241 | return -1;
|
| 242 | }
|
| 243 |
|
| 244 | ret=ioctl(fd, RPMSG_SET_INT_FLAG, NULL);
|
| 245 | if(ret<0){
|
| 246 | at_print(AT_DEBUG,"cap add ioctl FAIL\n");
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 247 | close(fd);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 248 | return AT_END;
|
| 249 | }
|
| 250 | ret=write(fd, &ctx, 4);
|
| 251 | if(ret<0){
|
| 252 | at_print(AT_DEBUG,"cap add write FAIL\n");
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 253 | close(fd);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 254 | return AT_END;
|
| 255 | }
|
| 256 |
|
| 257 | *res_msg = at_query_result_build("capadd_lock",strCmd);
|
| 258 | *res_msglen = strlen(*res_msg);
|
| 259 |
|
| 260 | close(fd);
|
| 261 |
|
| 262 | return AT_END;
|
| 263 | }
|
| 264 |
|
| 265 | static int pm_capdelete_wakelock(int at_fd,char * at_paras,void * *res_msg,int * res_msglen)
|
| 266 | {
|
| 267 | char strCmd[AT_CMD_MAX] = {0};
|
| 268 |
|
| 269 | unsigned int ctx=0x5a5b;
|
| 270 | int fd, ret;
|
| 271 |
|
| 272 | at_print(AT_DEBUG,"pm_capdelete_wakelock\n");
|
| 273 |
|
| 274 | fd =open(AT_CAP_DEV, O_RDWR);
|
| 275 | if(fd<0){
|
| 276 | at_print(AT_DEBUG,"cap add open FAIL\n");
|
| 277 | return -1;
|
| 278 | }
|
| 279 |
|
| 280 | ret=ioctl(fd, RPMSG_SET_INT_FLAG, NULL);
|
| 281 | if(ret<0){
|
| 282 | at_print(AT_DEBUG,"cap add ioctl FAIL\n");
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 283 | close(fd);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 284 | return AT_END;
|
| 285 | }
|
| 286 | ret=write(fd, &ctx, 4);
|
| 287 | if(ret<0){
|
| 288 | at_print(AT_DEBUG,"cap add write FAIL\n");
|
xf.li | 742dd02 | 2023-06-08 01:43:32 -0700 | [diff] [blame] | 289 | close(fd);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 290 | return AT_END;
|
| 291 | }
|
| 292 |
|
| 293 | close(fd);
|
| 294 |
|
| 295 | *res_msg = at_query_result_build("capdelete_lock",strCmd);
|
| 296 | *res_msglen = strlen(*res_msg);
|
| 297 |
|
| 298 | return AT_END;
|
| 299 | }
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 300 | void ext_wdt_regist_init(void)
|
| 301 | {
|
| 302 | //wdt_fd = open(ZX_SOFT_WDT_DEV, O_RDWR);
|
| 303 | //ioctl(wdt_fd, ZX_WDT_SET_CHECK, FALSE);
|
| 304 |
|
| 305 | register_serv_func2("WDT=", 0, 0, 0, wdt_act_func, NULL);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 306 | register_serv_func2("WDT?", 0, 0, 0,wdt_get_nv_state,NULL);
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 307 | register_serv_func2("WDTP=", 0, 0, 0, wdt_set_nv_priority, NULL);
|
xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 308 | register_serv_func2("WDTP?", 0, 0, 0,wdt_get_nv_priority,NULL);
|
| 309 |
|
| 310 | register_serv_func2("apadd_lock", 0, 0, 0,pm_apadd_wakelock,NULL);
|
| 311 | register_serv_func2("apdel_lock", 0, 0, 0,pm_apdelete_wakelock,NULL);
|
| 312 | register_serv_func2("capadd_lock", 0, 0, 0,pm_capadd_wakelock,NULL);
|
| 313 | register_serv_func2("capdel_lock", 0, 0, 0,pm_capdelete_wakelock,NULL);
|
lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 314 | }
|
| 315 |
|