Changeset 8a64320e in mainline for uspace/lib/ieee80211/src/ieee80211_iface_impl.c
- Timestamp:
- 2015-04-23T23:40:14Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- dcba819
- Parents:
- 09044cb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ieee80211/src/ieee80211_iface_impl.c
r09044cb r8a64320e 27 27 */ 28 28 29 /** @addtogroup libieee80211 30 * @{ 31 */ 32 33 /** @file ieee80211_iface_impl.c 34 * 35 * IEEE 802.11 default interface functions implementation. 36 */ 37 29 38 #include <str.h> 30 39 #include <errno.h> 31 32 40 #include <ieee80211_private.h> 33 41 #include <ieee80211_iface_impl.h> 34 42 35 /** @addtogroup libieee80211 36 * @{ 37 */ 38 39 /** @file ieee80211_iface_impl.c 40 * 41 * IEEE 802.11 default interface functions implementation. 42 */ 43 44 /** 45 * Implementation of fetching scan results. 46 * 47 * @param fun Device function. 43 /** Implementation of fetching scan results. 44 * 45 * @param fun Device function. 48 46 * @param results Structure where should be stored scan results. 49 * 50 * @return EOK if everything went OK, EREFUSED when device is not ready yet. 51 */ 52 int ieee80211_get_scan_results_impl(ddf_fun_t *fun, 53 ieee80211_scan_results_t *results, bool now) 47 * 48 * @return EOK if everything went OK, 49 * EREFUSED when device is not ready yet. 50 * 51 */ 52 int ieee80211_get_scan_results_impl(ddf_fun_t *fun, 53 ieee80211_scan_results_t *results, bool now) 54 54 { 55 55 nic_t *nic_data = nic_get_from_ddf_fun(fun); 56 56 ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data); 57 57 58 if (!ieee80211_is_ready(ieee80211_dev))58 if (!ieee80211_is_ready(ieee80211_dev)) 59 59 return EREFUSED; 60 60 61 if (now) {61 if (now) 62 62 ieee80211_dev->ops->scan(ieee80211_dev); 63 }64 63 65 64 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex); 66 if(results) { 65 66 if (results) { 67 67 ieee80211_scan_result_list_t *result_list = 68 69 70 int i = 0;68 &ieee80211_dev->ap_list; 69 70 unsigned int i = 0; 71 71 ieee80211_scan_result_list_foreach(*result_list, result) { 72 memcpy(&results->results[i], 73 &result->scan_result,74 72 memcpy(&results->results[i], 73 &result->scan_result, 74 sizeof(ieee80211_scan_result_t)); 75 75 i++; 76 76 } … … 78 78 results->length = i; 79 79 } 80 80 81 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex); 81 82 … … 88 89 } 89 90 90 /** 91 * Working procedure of connect function. 92 * 91 /** Working procedure of connect function. 92 * 93 93 * @param ieee80211_dev Pointer to IEEE 802.11 device. 94 * @param auth_data Selected AP data we want to connect to. 95 * 96 * @return EOK if everything OK, ETIMEOUT when timeout during authenticating. 94 * @param auth_data Selected AP data we want to connect to. 95 * 96 * @return EOK if everything OK, 97 * ETIMEOUT when timeout during authenticating. 98 * 97 99 */ 98 100 static int ieee80211_connect_proc(ieee80211_dev_t *ieee80211_dev, 99 101 ieee80211_scan_result_link_t *auth_data, char *password) 100 102 { 101 103 ieee80211_dev->bssid_info.res_link = auth_data; 102 104 103 105 /* Set channel. */ 104 int rc = ieee80211_dev->ops->set_freq(ieee80211_dev, 105 106 if (rc != EOK)106 int rc = ieee80211_dev->ops->set_freq(ieee80211_dev, 107 ieee80211_channel_to_freq(auth_data->scan_result.channel)); 108 if (rc != EOK) 107 109 return rc; 108 110 109 111 /* Try to authenticate. */ 110 112 ieee80211_authenticate(ieee80211_dev); 113 111 114 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 112 115 rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond, 113 &ieee80211_dev->gen_mutex, 114 AUTH_TIMEOUT); 116 &ieee80211_dev->gen_mutex, AUTH_TIMEOUT); 115 117 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 116 if(rc != EOK) 118 119 if (rc != EOK) 117 120 return rc; 118 if(ieee80211_get_auth_phase(ieee80211_dev) != 119 IEEE80211_AUTH_AUTHENTICATED) { 120 ieee80211_set_auth_phase(ieee80211_dev, 121 IEEE80211_AUTH_DISCONNECTED); 121 122 if (ieee80211_get_auth_phase(ieee80211_dev) != 123 IEEE80211_AUTH_AUTHENTICATED) { 124 ieee80211_set_auth_phase(ieee80211_dev, 125 IEEE80211_AUTH_DISCONNECTED); 122 126 return EINVAL; 123 127 } … … 125 129 /* Try to associate. */ 126 130 ieee80211_associate(ieee80211_dev, password); 131 127 132 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 128 133 rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond, 129 &ieee80211_dev->gen_mutex, 130 AUTH_TIMEOUT); 134 &ieee80211_dev->gen_mutex, AUTH_TIMEOUT); 131 135 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 132 if(rc != EOK) 136 137 if (rc != EOK) 133 138 return rc; 134 if(ieee80211_get_auth_phase(ieee80211_dev) != 135 IEEE80211_AUTH_ASSOCIATED) { 136 ieee80211_set_auth_phase(ieee80211_dev, 137 IEEE80211_AUTH_DISCONNECTED); 139 140 if (ieee80211_get_auth_phase(ieee80211_dev) != 141 IEEE80211_AUTH_ASSOCIATED) { 142 ieee80211_set_auth_phase(ieee80211_dev, 143 IEEE80211_AUTH_DISCONNECTED); 138 144 return EINVAL; 139 145 } 140 146 141 147 /* On open network, we are finished. */ 142 if(auth_data->scan_result.security.type != IEEE80211_SECURITY_OPEN) { 148 if (auth_data->scan_result.security.type != 149 IEEE80211_SECURITY_OPEN) { 143 150 /* Otherwise wait for 4-way handshake to complete. */ 151 144 152 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 145 153 rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond, 146 &ieee80211_dev->gen_mutex, 147 HANDSHAKE_TIMEOUT); 154 &ieee80211_dev->gen_mutex, HANDSHAKE_TIMEOUT); 148 155 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 149 if(rc != EOK) { 156 157 if (rc != EOK) { 150 158 ieee80211_deauthenticate(ieee80211_dev); 151 159 return rc; … … 158 166 } 159 167 160 /** 161 * Implementation of connecting to specified SSID. 162 * 163 * @param fun Device function. 168 /** Implementation of connecting to specified SSID. 169 * 170 * @param fun Device function. 164 171 * @param ssid_start SSID prefix of access point we want to connect to. 165 * 166 * @return EOK if everything OK, ETIMEOUT when timeout during authenticating, 167 * EINVAL when SSID not in scan results list, EPERM when incorrect password 168 * passed, EREFUSED when device is not ready yet. 172 * 173 * @return EOK if everything OK, 174 * ETIMEOUT when timeout during authenticating, 175 * EINVAL when SSID not in scan results list, 176 * EPERM when incorrect password passed, 177 * EREFUSED when device is not ready yet. 178 * 169 179 */ 170 180 int ieee80211_connect_impl(ddf_fun_t *fun, char *ssid_start, char *password) … … 173 183 assert(password); 174 184 175 int rc;176 177 185 nic_t *nic_data = nic_get_from_ddf_fun(fun); 178 186 ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data); 179 187 180 if (!ieee80211_is_ready(ieee80211_dev))188 if (!ieee80211_is_ready(ieee80211_dev)) 181 189 return EREFUSED; 182 190 183 if (ieee80211_is_connected(ieee80211_dev)) {184 rc = ieee80211_dev->iface->disconnect(fun);185 if (rc != EOK)191 if (ieee80211_is_connected(ieee80211_dev)) { 192 int rc = ieee80211_dev->iface->disconnect(fun); 193 if (rc != EOK) 186 194 return rc; 187 195 } … … 189 197 ieee80211_set_connect_request(ieee80211_dev); 190 198 191 rc = ENOENT;199 int rc = ENOENT; 192 200 fibril_mutex_lock(&ieee80211_dev->scan_mutex); 193 201 194 202 ieee80211_dev->pending_conn_req = false; 195 203 196 204 ieee80211_scan_result_list_foreach(ieee80211_dev->ap_list, result) { 197 if(!str_lcmp(ssid_start, 198 result->scan_result.ssid, 199 str_size(ssid_start))) { 205 if (!str_lcmp(ssid_start, result->scan_result.ssid, 206 str_size(ssid_start))) { 200 207 rc = ieee80211_connect_proc(ieee80211_dev, result, 201 208 password); 202 209 break; 203 210 } … … 209 216 } 210 217 211 /** 212 * Implementation of disconnecting device from network. 213 * 218 /** Implementation of disconnecting device from network. 219 * 214 220 * @param fun Device function. 215 * 216 * @return EOK if everything OK, EREFUSED if device is not ready yet. 221 * 222 * @return EOK if everything OK, 223 * EREFUSED if device is not ready yet. 224 * 217 225 */ 218 226 int ieee80211_disconnect_impl(ddf_fun_t *fun) … … 221 229 ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data); 222 230 223 if (!ieee80211_is_ready(ieee80211_dev))231 if (!ieee80211_is_ready(ieee80211_dev)) 224 232 return EREFUSED; 225 233 226 if (!ieee80211_is_connected(ieee80211_dev)) {234 if (!ieee80211_is_connected(ieee80211_dev)) 227 235 return EOK; 228 } else {229 230 231 232 return rc;233 }236 237 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex); 238 int rc = ieee80211_deauthenticate(ieee80211_dev); 239 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex); 240 241 return rc; 234 242 } 235 243
Note:
See TracChangeset
for help on using the changeset viewer.