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 _WIFI_HOST_SMARTCONF_H 16 #define _WIFI_HOST_SMARTCONF_H 17 18 #include "wb_co_int.h" 19 #include "wb_co_bool.h" 20 #include "wifi_msg.h" 21 #include "wifi_mac.h" 22 #include "rtos_ohos_al.h" 23 24 /// WPA message queue size 25 #define FHOST_SMARTCONF_QUEUE_WPA_MSG 5 26 /// Max buffer size used for WPA msg 27 #define FHOST_SMARTCONF_WPA_CTRL_BUF 256 28 /// Max ssid/pwd size 29 #define DATA_BUF_SIZE 32 30 31 #define MACDBG "%02x:%02x:%02x:%02x:%02x:%02x" 32 #define MAC2STRDBG(ea) (ea)[0], (ea)[1], (ea)[2], (ea)[3], (ea)[4], (ea)[5] 33 34 /// Types of encryption 35 typedef enum _encryption_mode { 36 /// Encryption has not yet been determined 37 UNKOWN_ENCRY = 0, 38 /// Open Network (no security at all) 39 ENCRY_NONE, 40 /// WPA/WPA2 + AES 41 ENCRY_CCMP, 42 /// WPA/WPA2 + TKIP 43 ENCRY_TKIP, 44 /// WEP encryption 45 ENCRY_WEP, 46 } ENCYTPTION_MODE; 47 48 /// smartconfig status 49 typedef enum sc_status { 50 /// Sniffing the different scan result channels 51 SC_STATUS_WAIT = 0, 52 /// Target channel is found 53 SC_STATUS_CHANNEL_FOUND, 54 /// SSID and PWD are found 55 SC_STATUS_SSID_PSWD_FOUND, 56 /// connected 57 SC_STATUS_CONNECTED 58 } SC_STATUS; 59 60 /// Structure for the scan results 61 struct fhost_smart_scan_res { 62 /// Channel definition 63 struct mac_chan_def *chan[SCAN_CHANNEL_MAX]; 64 /// Number of channels 65 uint16_t cnt; 66 }; 67 68 /// smartconf configuration structure 69 struct fhost_smart_conf { 70 /// vif idx 71 uint8_t idx; 72 /// Handle of smartconf task 73 rtos_task_handle smart_handle; 74 /// Smartconf semaphore used for synchronization 75 rtos_semaphore semaphore; 76 /// Keyphrase 77 char pwd[DATA_BUF_SIZE]; 78 /// SSID 79 char ssid[DATA_BUF_SIZE]; 80 /// Encryption protocol 81 uint8_t encryption_mode; 82 /// Smartconfig status 83 uint8_t status; 84 /// Packet source address 85 uint16_t src_mac_addr[MAC_ADDR_LEN / 2]; 86 /// Packet destination address 87 uint16_t dst_mac_addr[MAC_ADDR_LEN / 2]; 88 /// bssid mac address 89 uint16_t bssid_mac_addr[MAC_ADDR_LEN / 2]; 90 /// Guide pattern index 91 uint8_t pattern_idx; 92 /// CFGRWNX queue and sockets 93 struct fhost_cntrl_link *link_params; 94 /// Whether CFGRWNX link must be close when task exit 95 bool local_link; 96 /// Frequency on which the smartconfig algorithm is currently running 97 uint16_t freq; 98 /// Mac address is found (supported frame) 99 bool mac_addr_is_found; 100 101 struct smartconfig_t *sc; 102 }; 103 104 /// smartconf configuration 105 extern struct fhost_smart_conf smart_conf; 106 107 /// Encryption offset for supported frame 108 extern uint16_t rx_encry_offset[]; 109 /// Number of rx encryption types 110 extern uint8_t rx_encry_size; 111 112 /// Encryption offset for unsupported frame 113 extern uint16_t uf_encry_offset[]; 114 // Number of uf encryption types 115 extern uint8_t uf_encry_size; 116 117 /* 118 * FUNCTIONS 119 **************************************************************************************** 120 */ 121 /** 122 **************************************************************************************** 123 * @brief Create the smartconf task and the different queues associated to this task. 124 * 125 * @param[in] idx Index of the FHOST interface 126 * @param[in] link A CFGRWNX link. If NULL, a new link will be created. 127 * 128 * @return 0 on success and != 0 if error occurred. 129 **************************************************************************************** 130 */ 131 int fhost_smartconf_start(int idx, struct fhost_cntrl_link *link); 132 int fhost_smartconf_stop(void); 133 134 #endif // _WIFI_HOST_SMARTCONF_H 135