/* * Copyright (C) 2017 XRADIO TECHNOLOGY CO., LTD. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. * 3. Neither the name of XRADIO TECHNOLOGY CO., LTD. nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if CONFIG_MUTIL_NET_STACK #include "cmd_util.h" #include "driver/chip/hal_gpio.h" #include "xrlink/xrlink.h" #include "driver/component/axp/axp.h" #include "driver/component/axp/pmu_mg/pmu_manager.h" #include "kernel/os/os_timer.h" #include "common/cmd/cmd_defs.h" #include "debug/heap_trace.h" #include "kernel/os/os_time.h" #include "xr_blink.h" #include "net/wlan/wlan_ext_req.h" static enum cmd_status cmd_xrlink_pm_standby_exec(char *cmd) { xr_pmu_ctrl(ENTER_STANDBY); return CMD_STATUS_OK; } static enum cmd_status cmd_xrlink_pm_hibernation_exec(char *cmd) { xr_pmu_ctrl(ENTER_HIBERNATION); return CMD_STATUS_OK; } static enum cmd_status cmd_xrlink_pm_lowpower_exec(char *cmd) { uint32_t dtim; int ret; uint32_t cnt; cnt = cmd_sscanf(cmd, "d=%d", &dtim); if (cnt != 1) { printf("invalid param number %d\n", cnt); return CMD_STATUS_INVALID_ARG; } printf("dtim = %d\n", dtim); if (dtim > 30) { printf("dtim=%d parameters are out of rang\n", dtim); } ret = wlan_ext_low_power_param_set_default(dtim); if (ret) { printf("fail to set pre_rx_bcn!\n"); return CMD_STATUS_INVALID_ARG; } return CMD_STATUS_OK; } static const struct cmd_data g_xrlink_pm_cmds[] = { { "standby", cmd_xrlink_pm_standby_exec}, { "hibernation", cmd_xrlink_pm_hibernation_exec}, { "set_lowpower", cmd_xrlink_pm_lowpower_exec}, }; enum cmd_status cmd_xrlink_pm_exec(char *cmd) { return cmd_exec(cmd, g_xrlink_pm_cmds, cmd_nitems(g_xrlink_pm_cmds)); } enum cmd_status cmd_xrlink_init_exec(char *cmd) { return xradio_link_init(); } enum cmd_status cmd_xrlink_deinit_exec(char *cmd) { xradio_link_deinit(); return 0; } enum cmd_status cmd_xrlink_blink_exec(char *cmd) { xr_blink_start(); return 0; } #define XRLINK_VENDOR_MAX_LEN 1500 enum cmd_status cmd_xrlink_vendor_exec(char *cmd) { uint32_t cnt; uint32_t len; uint8_t *data = NULL; int i = 0; cnt = cmd_sscanf(cmd, "l=%d", &len); if (cnt != 1) { printf("invalid param number %d\n", cnt); return CMD_STATUS_INVALID_ARG; } printf("send vendor data length: %d\n", len); data = (uint8_t *)malloc(len); if (!data) { printf("No memory\n"); return CMD_STATUS_OK; } if (len >= XRLINK_VENDOR_MAX_LEN) { for (i = i; i < len / XRLINK_VENDOR_MAX_LEN; i++) { xradio_link_send_data(data + i * XRLINK_VENDOR_MAX_LEN, XRLINK_VENDOR_MAX_LEN); printf("send offset:%d,len:%d\n", i * XRLINK_VENDOR_MAX_LEN, XRLINK_VENDOR_MAX_LEN); } } if (len % XRLINK_VENDOR_MAX_LEN) { printf("send offset:%d, len:%d\n", i * XRLINK_VENDOR_MAX_LEN, len % XRLINK_VENDOR_MAX_LEN); xradio_link_send_data(data + i * XRLINK_VENDOR_MAX_LEN, len % XRLINK_VENDOR_MAX_LEN); } free(data); return CMD_STATUS_OK; } #endif /* CONFIG_MUTIL_NET_STACK */