1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef TLS_CMDP_H 17 #define TLS_CMDP_H 18 #include "wm_type_def.h" 19 #include "wm_params.h" 20 #include "wm_uart.h" 21 #include "wm_config.h" 22 23 /* error code */ 24 #define CMD_ERR_OK 0 25 #define CMD_ERR_INV_FMT 1 26 #define CMD_ERR_UNSUPP 2 27 #define CMD_ERR_OPS 3 28 #define CMD_ERR_INV_PARAMS 4 29 #define CMD_ERR_NOT_ALLOW 5 30 #define CMD_ERR_MEM 6 31 #define CMD_ERR_FLASH 7 32 #define CMD_ERR_BUSY 8 33 #define CMD_ERR_SLEEP 9 34 #define CMD_ERR_JOIN 10 35 #define CMD_ERR_NO_SKT 11 36 #define CMD_ERR_INV_SKT 12 37 #define CMD_ERR_SKT_CONN 13 38 #define CMD_ERR_SKT_SND 62 39 #define CMD_ERR_SKT_RPT 63 40 #define CMD_ERR_UNDEFINE 64 41 42 struct tls_socket_cfg { 43 u8 proto; /* 0: tcp, 1: udp */ 44 u8 client; 45 u16 port; 46 u8 host[32]; /* host name */ 47 u16 host_len; 48 u8 ip_addr[4]; 49 u32 timeout; 50 }; 51 52 struct tls_cmd_rsp_t { 53 u8 *rsp_ptr; 54 u32 max_size; 55 u32 rsp_len; 56 u8 res[0]; 57 }; 58 59 enum tls_cmd_mode { 60 CMD_MODE_HSPI_ATCMD, 61 CMD_MODE_HSPI_RICMD, 62 CMD_MODE_UART0_ATCMD, 63 CMD_MODE_UART1_ATCMD, 64 CMD_MODE_UART1_RICMD, 65 #if TLS_CONFIG_RMMS 66 CMD_MODE_RMMS_ATCMD, 67 #endif 68 CMD_MODE_INTERNAL, 69 }; 70 71 enum { 72 UART_ATCMD_MODE = 0, 73 UART_RICMD_MODE = 1, 74 UART_TRANS_MODE = 2, 75 UART_ATDATA_MODE = 3, 76 UART_ATSND_MODE = 4, 77 }; 78 79 struct tls_cmd_ps_t { 80 u8 ps_type; 81 u8 wake_type; 82 u32 delay_time; 83 u32 wake_time; 84 }; 85 86 struct tls_cmd_ver_t { 87 u8 hw_ver[6]; 88 u8 fw_ver[4]; 89 }; 90 91 #ifndef ETH_ALEN 92 #define ETH_ALEN 6 93 #endif 94 struct tls_cmd_connect_t { 95 u8 bssid[ETH_ALEN]; 96 u8 type; 97 u8 channel; 98 u8 encrypt; 99 u8 ssid_len; 100 u8 ssid[32]; 101 u8 rssi; /* 只取值,不取符号 */ 102 u8 res; /* 1: 返回参数, 0: 没有参数 */ 103 }; 104 105 struct tls_cmd_link_status_t { 106 u8 ip[4]; 107 u8 netmask[4]; 108 u8 gw[4]; 109 u8 dns1[4]; 110 u8 dns2[4]; 111 u8 status; 112 }; 113 114 struct tls_cmd_socket_t { 115 u32 timeout; 116 u8 ip_addr[4]; 117 u8 proto; 118 u8 client; 119 u16 port; 120 char host_name[32]; 121 u8 host_len; 122 u16 localport; 123 }; 124 125 struct tls_cmd_ssid_t { 126 u8 ssid_len; 127 u8 ssid[32]; 128 }; 129 130 struct tls_cmd_tem_t { 131 u8 offsetLen; 132 s32 offset; 133 }; 134 135 struct tls_cmd_key_t { 136 u8 format; 137 u8 index; 138 u8 key_len; 139 u8 key[64]; 140 }; 141 142 struct tls_cmd_bssid_t { 143 u8 bssid[6]; 144 u8 enable; 145 }; 146 147 struct tls_cmd_wl_hw_mode_t { 148 u8 hw_mode; 149 u8 max_rate; 150 }; 151 152 struct tls_cmd_wps_params_t { 153 u8 mode; 154 u8 pin_len; 155 u8 pin[8]; 156 }; 157 158 struct tls_cmd_ip_params_t { 159 u8 ip_addr[4]; 160 u8 netmask[4]; 161 u8 gateway[4]; 162 u8 dns[4]; 163 u8 type; 164 }; 165 166 struct tls_cmd_uart_params_t { 167 u32 baud_rate; 168 u32 stop_bit; 169 u32 parity; 170 u32 flow_ctrl; 171 u32 charlength; 172 }; 173 174 struct tls_cmd_flash_t { 175 u32 word_cnt; 176 u32 flash_addr; 177 u32 value[8]; 178 }; 179 void tls_cmd_set_net_up(u8 netup); 180 u8 tls_cmd_get_net_up(void); 181 u8 tls_cmd_get_auto_mode(void); 182 struct tls_socket_cfg *tls_cmd_get_socket_cfg(void); 183 void tls_cmd_init_socket_cfg(void); 184 int hostif_cipher2host(int cipher, int proto); 185 int tls_cmd_ps(struct tls_cmd_ps_t *ps); 186 int tls_cmd_reset_flash(void); 187 int tls_cmd_pmtf(void); 188 void tls_cmd_reset_sys(void); 189 int tls_cmd_get_ver(struct tls_cmd_ver_t *ver); 190 int tls_cmd_scan(enum tls_cmd_mode mode); 191 int tls_cmd_scan_by_param(enum tls_cmd_mode mode, u16 channellist, u32 times, u16 switchinterval); 192 int tls_cmd_join(enum tls_cmd_mode mode, struct tls_cmd_connect_t *conn); 193 int tls_cmd_disconnect_network(u8 mode); 194 int tls_cmd_get_link_status(struct tls_cmd_link_status_t *lks); 195 int tls_cmd_wps_start(void); 196 int tls_cmd_set_wireless_mode(u8 mode, u8 update_flash); 197 int tls_cmd_get_wireless_mode(u8 *mode); 198 int tls_cmd_set_ssid(struct tls_cmd_ssid_t *ssid, u8 update_flash); 199 int tls_cmd_get_ssid(struct tls_cmd_ssid_t *ssid); 200 int tls_cmd_set_key(struct tls_cmd_key_t *key, u8 update_flash); 201 int tls_cmd_get_key(struct tls_cmd_key_t *key); 202 int tls_cmd_set_encrypt(u8 encrypt, u8 update_flash); 203 int tls_cmd_get_encrypt(u8 *encrypt); 204 int tls_cmd_set_bssid(struct tls_cmd_bssid_t *bssid, u8 update_flash); 205 int tls_cmd_get_bssid(struct tls_cmd_bssid_t *bssid); 206 int tls_cmd_get_original_ssid(struct tls_param_ssid *original_ssid); 207 int tls_cmd_get_original_key(struct tls_param_original_key *original_key); 208 int tls_cmd_set_hide_ssid(u8 ssid_set, u8 update_flash); 209 int tls_cmd_get_hide_ssid(u8 *ssid_set); 210 int tls_cmd_set_channel(u8 channel, u8 channel_en, u8 update_flash); 211 int tls_cmd_get_channel(u8 *channel, u8 *channel_en); 212 int tls_cmd_set_channellist(u16 channellist, u8 update_flash); 213 int tls_cmd_get_channellist(u16 *channellist); 214 int tls_cmd_set_region(u16 region, u8 update_flash); 215 int tls_cmd_get_region(u16 *region); 216 int tls_cmd_set_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode, u8 update_flash); 217 int tls_cmd_get_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode); 218 int tls_cmd_set_adhoc_create_mode(u8 mode, u8 update_flash); 219 int tls_cmd_get_adhoc_create_mode(u8 *mode); 220 int tls_cmd_set_wl_ps_mode(u8 enable, u8 update_flash); 221 int tls_cmd_get_wl_ps_mode(u8 *enable); 222 int tls_cmd_set_roaming_mode(u8 enable, u8 update_flash); 223 int tls_cmd_get_roaming_mode(u8 *enable); 224 int tls_cmd_set_wps_params(struct tls_cmd_wps_params_t *params, u8 update_flash); 225 int tls_cmd_get_wps_params(struct tls_cmd_wps_params_t *params); 226 int tls_cmd_get_ip_info(struct tls_cmd_ip_params_t *params); 227 int tls_cmd_set_ip_info(struct tls_cmd_ip_params_t *params, u8 update_flash); 228 int tls_cmd_set_work_mode(u8 mode, u8 update_flash); 229 int tls_cmd_get_work_mode(u8 *mode); 230 int tls_cmd_get_hostif_mode(u8 *mode); 231 int tls_cmd_set_hostif_mode(u8 mode, u8 update_flash); 232 int tls_cmd_set_default_socket_params(struct tls_cmd_socket_t *params, u8 update_flash); 233 int tls_cmd_get_default_socket_params(struct tls_cmd_socket_t *params); 234 int tls_cmd_get_uart_params(struct tls_cmd_uart_params_t *params); 235 int tls_cmd_set_uart_params(struct tls_cmd_uart_params_t *params, u8 update_flash); 236 int tls_cmd_get_atlt(u16 *length); 237 int tls_cmd_set_atlt(u16 length, u8 update_flash); 238 int tls_cmd_get_atpt(u16 *period); 239 int tls_cmd_set_atpt(u16 period, u8 update_flash); 240 int tls_cmd_get_espc(u8 *escapechar); 241 int tls_cmd_set_espc(u8 escapechar, u8 update_flash); 242 int tls_cmd_get_espt(u16 *escapeperiod); 243 int tls_cmd_set_espt(u16 escapeperiod, u8 update_flash); 244 int tls_cmd_get_warc(u8 *autoretrycnt); 245 int tls_cmd_set_warc(u8 autoretrycnt, u8 update_flash); 246 int tls_cmd_set_dnsname(u8 *dnsname, u8 update_flash); 247 int tls_cmd_get_dnsname(u8 *dnsname); 248 int tls_cmd_set_webs(struct tls_webs_cfg webcfg, u8 update_flash); 249 int tls_cmd_get_webs(struct tls_webs_cfg *webcfg); 250 int tls_cmd_get_cmdm(u8 *cmdmode); 251 int tls_cmd_set_cmdm(u8 cmdmode, u8 update_flash); 252 int tls_cmd_get_iom(u8 *iomode); 253 int tls_cmd_set_iom(u8 iomode, u8 update_flash); 254 int tls_cmd_set_oneshot(u8 oneshotflag, u8 update_flash); 255 int tls_cmd_get_oneshot(u8 *oneshotflag); 256 int tls_cmd_get_pass(u8 *password); 257 int tls_cmd_set_pass(u8* password, u8 update_flash); 258 259 int tls_cmd_set_dbg(u32 dbg); 260 int tls_cmd_wr_flash(struct tls_cmd_flash_t *wr_flash); 261 int tls_cmd_get_sha1(u8 *psk); 262 int tls_cmd_set_sha1(u8* psk, u8 update_flash); 263 264 void tls_set_fwup_mode(u8 flag); 265 u8 tls_get_fwup_mode(void); 266 267 int tls_cmd_set_wps_pin(struct tls_param_wps* wps, u8 update_flash); 268 int tls_cmd_get_wps_pin(struct tls_param_wps *wps); 269 typedef void (*cmd_get_uart1_port_callback)(struct tls_uart_port **uart1_port); 270 void tls_cmd_register_get_uart1_port(cmd_get_uart1_port_callback callback); 271 cmd_get_uart1_port_callback tls_cmd_get_uart1_port(void); 272 273 typedef void (*cmd_set_uart1_mode_callback)(u32 cmd_mode); 274 void tls_cmd_register_set_uart1_mode(cmd_set_uart1_mode_callback callback); 275 cmd_set_uart1_mode_callback tls_cmd_get_set_uart1_mode(void); 276 277 typedef void (*cmd_set_uart1_sock_param_callback)(u16 sksnd_cnt, bool rx_idle); 278 void tls_cmd_register_set_uart1_sock_param(cmd_set_uart1_sock_param_callback callback); 279 cmd_set_uart1_sock_param_callback tls_cmd_get_set_uart1_sock_param(void); 280 281 typedef void (*cmd_set_uart0_mode_callback)(u32 cmd_mode); 282 cmd_set_uart0_mode_callback tls_cmd_get_set_uart0_mode(void); 283 void tls_cmd_register_set_uart0_mode(cmd_set_uart0_mode_callback callback); 284 285 int tls_cmd_get_hw_ver(u8 *hwver); 286 int tls_cmd_set_hw_ver(u8 *hwver); 287 288 #if TLS_CONFIG_AP 289 int tls_cmd_set_softap_ssid(struct tls_cmd_ssid_t *ssid, u8 update_flash); 290 int tls_cmd_get_softap_ssid(struct tls_cmd_ssid_t *ssid); 291 int tls_cmd_set_softap_key(struct tls_cmd_key_t *key, u8 update_flash); 292 int tls_cmd_get_softap_key(struct tls_cmd_key_t *key); 293 int tls_cmd_set_softap_encrypt(u8 encrypt, u8 update_flash); 294 int tls_cmd_get_softap_encrypt(u8 *encrypt); 295 int tls_cmd_get_softap_channel(u8 *channel); 296 int tls_cmd_set_softap_channel(u8 channel, u8 update_flash); 297 int tls_cmd_set_softap_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode, u8 update_flash); 298 int tls_cmd_get_softap_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode); 299 int tls_cmd_get_softap_ip_info(struct tls_cmd_ip_params_t *params); 300 int tls_cmd_set_softap_ip_info(struct tls_cmd_ip_params_t *params, u8 update_flash); 301 int tls_cmd_get_softap_link_status(struct tls_cmd_link_status_t *lks); 302 int tls_cmd_get_sta_detail(u32 *sta_num, u8 *buf); 303 304 #endif 305 306 #endif /* end of TLS_CMDP_H */ 307