1 /* 2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., 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 #ifndef _WLAN_IF_H_ 16 #define _WLAN_IF_H_ 17 18 #include "wifi_mac.h" 19 20 /** 21 **************************************************************************************** 22 * @brief * wlan_start_sta : Start STA to connect to router, until obtain IP address 23 * or timeout 24 * 25 * @param[] ssid: router name 26 * pw : router's password(if open, set NULL) 27 * timeout_ms: 0 -> 10000, -1 -> no timeout, (timeout_ms > 0 && bit0 is 1) -> wep 28 * @return value: -1:password < 8, -6: dhcp fail 29 **************************************************************************************** 30 */ 31 int wlan_start_sta(uint8_t *ssid, uint8_t *pw, int timeout_ms); 32 /** 33 **************************************************************************************** 34 * @brief * wlan_disconnect_sta : STA disconnect 35 * 36 * @param[] idx: 0 37 * @return value: 1: fail, 0: success 38 **************************************************************************************** 39 */ 40 int wlan_disconnect_sta(uint8_t idx); 41 /** 42 **************************************************************************************** 43 * @brief * wlan_dhcp : run dhcp client, if using 'wlan_start_sta', no need to call it 44 * 45 * @param[] net_if: 46 * @return value: 0: success 47 **************************************************************************************** 48 */ 49 int wlan_dhcp(net_if_t *net_if); 50 /** 51 **************************************************************************************** 52 * @brief * wlan_get_connect_status : get STA connect status 53 * 54 * @param[] none 55 * @return value: 0: disconnected, 1: connected 56 **************************************************************************************** 57 */ 58 int wlan_get_connect_status(void); 59 /** 60 **************************************************************************************** 61 * @brief * set_sta_connect_chan_num : Set channel num before calling 'wlan_start_sta', 62 * if kowns the router's channel num 63 * 64 * @param[] chan_num : channel number 65 **************************************************************************************** 66 */ 67 void set_sta_connect_chan_num(uint32_t chan_num); 68 69 /** 70 **************************************************************************************** 71 * @brief * wlan_start_ap : Create softAP 72 * 73 * @param[] band: 0 -> 2.4G, 1 -> 5G 74 * ssid: name 75 * pw : password(if open, set NULL) 76 * @return value: -1: fail, 0: success 77 **************************************************************************************** 78 */ 79 int wlan_start_ap(uint8_t band, uint8_t *ssid, uint8_t *pw); 80 81 /** 82 **************************************************************************************** 83 * @brief * wlan_stop_ap : Stop softAP 84 * 85 * @param[] none 86 * @return value: -1: fail, 0: success 87 **************************************************************************************** 88 */ 89 int wlan_stop_ap(void); 90 91 /** 92 **************************************************************************************** 93 * @brief * wlan_ap_switch_channel : softAP switch to specified channel 94 * 95 * @param[] chan_num: channel number 96 * @return value: -1: fail, 0: success 97 **************************************************************************************** 98 */ 99 int wlan_ap_switch_channel(uint8_t chan_num); 100 /** 101 **************************************************************************************** 102 * @brief * wlan_ap_disassociate_sta : softAP disassociate specified STA 103 * 104 * @param[] macaddr: mac address of specified STA 105 * @return value: -1: fail, 0: success 106 **************************************************************************************** 107 */ 108 int wlan_ap_disassociate_sta(struct mac_addr *macaddr); 109 /** 110 **************************************************************************************** 111 * @brief * All the bellow API related to AP should be called before 'wlan_start_ap' 112 **************************************************************************************** 113 */ 114 115 /** 116 **************************************************************************************** 117 * @brief * set_ap_ip_addr : Set IP start address for softAP 118 * 119 * @param[] new_ip_addr: IP address 120 * Default: (192 | (168 << 8) | (88 << 16) | (1 << 24)) 121 **************************************************************************************** 122 */ 123 void set_ap_ip_addr(uint32_t new_ip_addr); 124 /** 125 **************************************************************************************** 126 * @brief * set_ap_subnet_mask : Set subnet mask for softAP 127 * 128 * @param[] new_mask: subnet mask 129 * Default: 255.255.255.0 -> 0x00FFFFFF 130 **************************************************************************************** 131 */ 132 void set_ap_subnet_mask(uint32_t new_mask); 133 /** 134 **************************************************************************************** 135 * @brief * set_ap_bcn_interval : Set Beacon interval for softAP 136 * 137 * @param[] bcn_interval_ms: beacon interval(unit:ms) 138 * Default: 100 139 **************************************************************************************** 140 */ 141 void set_ap_bcn_interval(uint32_t bcn_interval_ms); 142 143 /** 144 **************************************************************************************** 145 * @brief * set_ap_channel_num : Set channel number for softAP, if not set, auto select 146 * 147 * @param[] num: channel nuber, 2.4G(1~14), 5G(depend on 'fhost_chan') 148 **************************************************************************************** 149 */ 150 void set_ap_channel_num(uint8_t num); 151 /** 152 **************************************************************************************** 153 * @brief * set_ap_hidden_ssid : Set hidden ssid for softAP 154 * 155 * @param[] val: 0 -> unhidden, 1 -> hidden 156 **************************************************************************************** 157 */ 158 void set_ap_hidden_ssid(uint8_t val); 159 /** 160 **************************************************************************************** 161 * @brief * set_ap_enable_he_rate : Enable HE rate for softAP 162 * 163 * @param[] en: 1 -> enable, 0(Default) -> diable 164 **************************************************************************************** 165 */ 166 void set_ap_enable_he_rate(uint8_t en); 167 /** 168 **************************************************************************************** 169 * @brief * set_ap_allow_sta_inactivity_s : Set max inactivity time for connected STA (if 170 * long time not receive/transmit, send a NULL 171 * frame to detect it. If detected fail, 172 * disassociate it). 173 * 174 * @param[] s: default -> 60s 175 **************************************************************************************** 176 */ 177 void set_ap_allow_sta_inactivity_s(uint8_t s); 178 179 /** 180 **************************************************************************************** 181 * @brief * wlan_start_wps : Start push button WPS 182 * 183 * @param[] none 184 * @return value: 0: success 185 **************************************************************************************** 186 */ 187 int wlan_start_wps(void); 188 189 /** 190 **************************************************************************************** 191 * @brief * wlan_ap_generate_ssid_pw_for_pairing & wlan_sta_auto_pairing are used as pairing 192 * 193 * @param[] out: ssid, pw 194 * in : times: paring retry times 195 * @return value: 0: success 196 **************************************************************************************** 197 */ 198 int wlan_ap_generate_ssid_pw_for_pairing(char *ssid, char *pw); 199 int wlan_sta_auto_pairing(char *ssid, char *pw, int8_t times); 200 201 uint32_t get_ap_ip_addr(void); 202 uint32_t get_ap_subnet_mask(void); 203 uint8_t *get_selected_channel_numbers(uint8_t band); 204 uint32_t get_sta_connect_chan_freq(void); 205 206 #if (PLF_BT_STACK || PLF_BLE_STACK) && (PLF_WIFI_STACK) 207 __WEAK void wb_coex_wifi_on_set(int on); 208 __WEAK void wb_coex_wifi_connected_set(int connected); 209 __WEAK int wb_coex_bt_connected_get(void); 210 __WEAK int wb_coex_bt_a2dp_on_get(void); 211 __WEAK int wb_coex_bt_sco_on_get(void); 212 #endif 213 214 extern uint8_t is_fixed_ip; 215 extern uint32_t fixed_ip, fixed_gw, fixed_mask; 216 extern uint8_t disconnected_by_user; 217 #endif /* _WLAN_IF_H_ */ 218