Changeset 053fc2b in mainline for uspace/lib/ieee80211
- Timestamp:
- 2015-04-10T13:52:11Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a931b7b
- Parents:
- d7dadcb4
- Location:
- uspace/lib/ieee80211
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ieee80211/include/ieee80211.h
rd7dadcb4 r053fc2b 60 60 #define IEEE80211_MAX_AMPDU_FACTOR 13 61 61 62 /* Max passphrase length in WPA/WPA2 protocols. */63 #define IEEE80211_ WPA_MAX_PASSWORD_LENGTH6462 /* Max authentication password length. */ 63 #define IEEE80211_MAX_PASSW_LEN 64 64 64 65 65 /** IEEE 802.11 b/g supported data rates in units of 500 kb/s. */ … … 139 139 * 140 140 * @param ieee80211_dev Pointer to IEEE 802.11 device structure. 141 * 142 * @return EOK if succeed, negative error code otherwise. 143 */ 144 int (*bssid_change)(struct ieee80211_dev *); 141 * @param connected True if connected to new BSSID, otherwise false. 142 * 143 * @return EOK if succeed, negative error code otherwise. 144 */ 145 int (*bssid_change)(struct ieee80211_dev *, bool); 145 146 146 147 /** … … 181 182 uint16_t freq); 182 183 extern uint16_t ieee80211_get_aid(ieee80211_dev_t* ieee80211_dev); 183 extern int ieee80211_get_ security_suite(ieee80211_dev_t* ieee80211_dev);184 extern int ieee80211_get_pairwise_security(ieee80211_dev_t* ieee80211_dev); 184 185 extern bool ieee80211_is_ready(ieee80211_dev_t* ieee80211_dev); 185 186 extern void ieee80211_set_ready(ieee80211_dev_t* ieee80211_dev, bool ready); -
uspace/lib/ieee80211/include/ieee80211_impl.h
rd7dadcb4 r053fc2b 47 47 extern int ieee80211_set_freq_impl(ieee80211_dev_t *ieee80211_dev, 48 48 uint16_t freq); 49 extern int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev); 49 extern int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev, 50 bool connected); 50 51 extern int ieee80211_key_config_impl(ieee80211_dev_t *ieee80211_dev, 51 52 ieee80211_key_config_t *key_conf, bool insert); -
uspace/lib/ieee80211/include/ieee80211_private.h
rd7dadcb4 r053fc2b 54 54 #define HANDSHAKE_TIMEOUT 3000000 55 55 56 /* Max period to rerun scan. */ 57 #define MAX_SCAN_SPAN_SEC 30 56 /* Scanning period. */ 57 #define SCAN_PERIOD_USEC 35000000 58 59 /* Time to wait for beacons on channel. */ 60 #define SCAN_CHANNEL_WAIT_USEC 200000 58 61 59 62 /* Max time to keep scan result. */ … … 187 190 IEEE80211_AUTH_DISCONNECTED, 188 191 IEEE80211_AUTH_AUTHENTICATED, 189 IEEE80211_AUTH_ASSOCIATED 192 IEEE80211_AUTH_ASSOCIATED, 193 IEEE80211_AUTH_CONNECTED 190 194 } ieee80211_auth_phase_t; 191 195 … … 202 206 typedef struct { 203 207 list_t list; 204 time_t last_scan; 205 fibril_mutex_t scan_mutex; 208 fibril_mutex_t results_mutex; 206 209 size_t size; 207 210 } ieee80211_scan_result_list_t; … … 210 213 typedef struct { 211 214 uint16_t aid; 212 char password[IEEE80211_ WPA_MAX_PASSWORD_LENGTH];215 char password[IEEE80211_MAX_PASSW_LEN]; 213 216 uint8_t ptk[MAX_PTK_LENGTH]; 214 217 uint8_t gtk[MAX_GTK_LENGTH]; … … 256 259 /** Current authentication phase. */ 257 260 ieee80211_auth_phase_t current_auth_phase; 261 262 /** Flag indicating whether client wants connect to network. */ 263 bool pending_conn_req; 264 265 /** Scanning guard. */ 266 fibril_mutex_t scan_mutex; 258 267 259 268 /** General purpose guard. */ … … 368 377 { 369 378 list_initialize(&results->list); 370 fibril_mutex_initialize(&results-> scan_mutex);379 fibril_mutex_initialize(&results->results_mutex); 371 380 } 372 381 … … 387 396 } 388 397 398 extern void ieee80211_set_connect_request(ieee80211_dev_t *ieee80211_dev); 399 extern bool ieee80211_pending_connect_request(ieee80211_dev_t *ieee80211_dev); 400 extern ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t 401 *ieee80211_dev); 402 extern void ieee80211_set_auth_phase(ieee80211_dev_t *ieee80211_dev, 403 ieee80211_auth_phase_t auth_phase); 389 404 extern int ieee80211_probe_request(ieee80211_dev_t *ieee80211_dev, 390 405 char *ssid); -
uspace/lib/ieee80211/src/ieee80211.c
rd7dadcb4 r053fc2b 51 51 #define IEEE80211_EXT_DATA_RATES_SIZE 4 52 52 53 #define ATOMIC_GET(state) 54 53 55 /** Frame encapsulation used in IEEE 802.11. */ 54 56 static const uint8_t rfc1042_header[] = { … … 282 284 ieee80211_dev) 283 285 { 284 return ieee80211_dev->current_op_mode; 286 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 287 ieee80211_operating_mode_t op_mode = ieee80211_dev->current_op_mode; 288 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 289 290 return op_mode; 285 291 } 286 292 … … 294 300 uint16_t ieee80211_query_current_freq(ieee80211_dev_t* ieee80211_dev) 295 301 { 296 return ieee80211_dev->current_freq; 302 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 303 uint16_t current_freq = ieee80211_dev->current_freq; 304 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 305 306 return current_freq; 297 307 } 298 308 299 309 /** 300 310 * Query BSSID the device is connected to. 311 * 312 * Note: Expecting locked results_mutex. 301 313 * 302 314 * @param ieee80211_dev IEEE 802.11 device. … … 306 318 nic_address_t *bssid) 307 319 { 320 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 321 308 322 if(bssid) { 309 ieee80211_scan_result_t *auth_data = 310 &ieee80211_dev->bssid_info.res_link->scan_result; 311 312 memcpy(bssid, (void *)&auth_data->bssid, sizeof(nic_address_t)); 313 } 323 ieee80211_scan_result_link_t *res_link = 324 ieee80211_dev->bssid_info.res_link; 325 326 if(res_link) { 327 memcpy(bssid, &res_link->scan_result.bssid, 328 sizeof(nic_address_t)); 329 } else { 330 nic_address_t broadcast_addr; 331 memcpy(broadcast_addr.address, 332 ieee80211_broadcast_mac_addr, 333 ETH_ADDR); 334 memcpy(bssid, &broadcast_addr, sizeof(nic_address_t)); 335 } 336 } 337 338 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 314 339 } 315 340 … … 323 348 uint16_t ieee80211_get_aid(ieee80211_dev_t* ieee80211_dev) 324 349 { 325 return ieee80211_dev->bssid_info.aid; 326 } 327 328 /** 329 * Get security suite used for HW encryption. 350 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 351 uint16_t aid = ieee80211_dev->bssid_info.aid; 352 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 353 354 return aid; 355 } 356 357 /** 358 * Get pairwise security suite used for HW encryption. 330 359 * 331 360 * @param ieee80211_dev IEEE 802.11 device. … … 333 362 * @return Security suite indicator. 334 363 */ 335 int ieee80211_get_security_suite(ieee80211_dev_t* ieee80211_dev) 336 { 364 int ieee80211_get_pairwise_security(ieee80211_dev_t* ieee80211_dev) 365 { 366 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 337 367 ieee80211_scan_result_link_t *auth_link = 338 368 ieee80211_dev->bssid_info.res_link; 339 340 return auth_link->scan_result.security.pair_alg; 369 int suite = auth_link->scan_result.security.pair_alg; 370 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 371 372 return suite; 341 373 } 342 374 … … 350 382 bool ieee80211_is_connected(ieee80211_dev_t* ieee80211_dev) 351 383 { 352 return ieee80211_dev->current_auth_phase == IEEE80211_AUTH_ASSOCIATED; 384 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 385 bool conn_state = 386 ieee80211_dev->current_auth_phase == IEEE80211_AUTH_CONNECTED; 387 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 388 return conn_state; 389 } 390 391 void ieee80211_set_auth_phase(ieee80211_dev_t *ieee80211_dev, 392 ieee80211_auth_phase_t auth_phase) 393 { 394 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 395 ieee80211_dev->current_auth_phase = auth_phase; 396 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 397 } 398 399 ieee80211_auth_phase_t ieee80211_get_auth_phase(ieee80211_dev_t 400 *ieee80211_dev) 401 { 402 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 403 ieee80211_auth_phase_t conn_state = ieee80211_dev->current_auth_phase; 404 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 405 return conn_state; 406 } 407 408 void ieee80211_set_connect_request(ieee80211_dev_t *ieee80211_dev) 409 { 410 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 411 ieee80211_dev->pending_conn_req = true; 412 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 413 } 414 415 bool ieee80211_pending_connect_request(ieee80211_dev_t *ieee80211_dev) 416 { 417 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 418 bool conn_request = ieee80211_dev->pending_conn_req; 419 ieee80211_dev->pending_conn_req = false; 420 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 421 return conn_request; 353 422 } 354 423 … … 362 431 ieee80211_operating_mode_t op_mode) 363 432 { 433 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 364 434 ieee80211_dev->current_op_mode = op_mode; 435 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 365 436 } 366 437 … … 374 445 uint16_t freq) 375 446 { 447 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 376 448 ieee80211_dev->current_freq = freq; 449 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 377 450 } 378 451 … … 408 481 extern bool ieee80211_query_using_key(ieee80211_dev_t* ieee80211_dev) 409 482 { 410 return ieee80211_dev->using_hw_key; 483 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 484 bool using_key = ieee80211_dev->using_hw_key; 485 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 486 487 return using_key; 411 488 } 412 489 … … 414 491 bool using_key) 415 492 { 493 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 416 494 ieee80211_dev->using_hw_key = using_key; 495 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 496 } 497 498 static int ieee80211_scan(void *arg) 499 { 500 assert(arg); 501 502 ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) arg; 503 504 while(true) { 505 ieee80211_dev->ops->scan(ieee80211_dev); 506 async_usleep(35000000); 507 } 508 509 return EOK; 417 510 } 418 511 … … 439 532 return rc; 440 533 441 rc = ieee80211_dev->ops->scan(ieee80211_dev); 442 if(rc != EOK) 443 return rc; 534 /* Add scanning fibril. */ 535 fid_t fibril = fibril_create(ieee80211_scan, ieee80211_dev); 536 if (fibril == 0) { 537 return ENOMEM; 538 } 539 fibril_add_ready(fibril); 444 540 445 541 return EOK; … … 458 554 nic_get_specific(nic); 459 555 460 if(!ieee80211_is_connected(ieee80211_dev)) { 556 ieee80211_auth_phase_t auth_phase = 557 ieee80211_get_auth_phase(ieee80211_dev); 558 if(auth_phase != IEEE80211_AUTH_ASSOCIATED && 559 auth_phase != IEEE80211_AUTH_CONNECTED) { 461 560 return; 462 561 } … … 478 577 memset(add_data, 0, 8); 479 578 480 if(ieee80211_ dev->using_hw_key) {579 if(ieee80211_query_using_key(ieee80211_dev)) { 481 580 int sec_suite = auth_data->security.pair_alg; 482 581 switch(sec_suite) { … … 630 729 ieee80211_dev->ready = false; 631 730 ieee80211_dev->using_hw_key = false; 731 ieee80211_dev->pending_conn_req = false; 632 732 ieee80211_dev->current_op_mode = IEEE80211_OPMODE_STATION; 633 733 ieee80211_dev->current_auth_phase = IEEE80211_AUTH_DISCONNECTED; … … 637 737 ieee80211_scan_result_list_init(&ieee80211_dev->ap_list); 638 738 739 fibril_mutex_initialize(&ieee80211_dev->scan_mutex); 639 740 fibril_mutex_initialize(&ieee80211_dev->gen_mutex); 640 741 fibril_condvar_initialize(&ieee80211_dev->gen_cond); … … 923 1024 924 1025 /* 925 * Save password and SSID to be used in eventual authentication 926 * handshake. 1026 * Save password to be used in eventual authentication handshake. 927 1027 */ 1028 memset(ieee80211_dev->bssid_info.password, 0, IEEE80211_MAX_PASSW_LEN); 928 1029 memcpy(ieee80211_dev->bssid_info.password, password, 929 1030 str_size(password)); … … 945 1046 ieee80211_scan_result_t *auth_data = 946 1047 &ieee80211_dev->bssid_info.res_link->scan_result; 947 948 ieee80211_dev->current_auth_phase = IEEE80211_AUTH_DISCONNECTED;949 ieee80211_dev->bssid_info.aid = (uint16_t) -1;950 memcpy(auth_data->bssid.address, ieee80211_broadcast_mac_addr,951 ETH_ADDR);952 1048 953 1049 nic_t *nic = nic_get_from_ddf_dev(ieee80211_dev->ddf_dev); … … 975 1071 free(buffer); 976 1072 977 ieee80211_dev->ops->bssid_change(ieee80211_dev); 1073 ieee80211_dev->bssid_info.res_link = NULL; 1074 ieee80211_dev->ops->bssid_change(ieee80211_dev, false); 1075 1076 if(ieee80211_query_using_key(ieee80211_dev)) 1077 ieee80211_dev->ops->key_config(ieee80211_dev, NULL, false); 1078 1079 ieee80211_set_auth_phase(ieee80211_dev, IEEE80211_AUTH_DISCONNECTED); 978 1080 979 1081 return EOK; … … 1121 1223 /* Not empty SSID. */ 1122 1224 if(ssid_ie_header->length > 0) { 1123 fibril_mutex_t *scan_mutex = &ieee80211_dev->ap_list.scan_mutex;1124 1125 fibril_mutex_lock(scan_mutex);1126 1127 1225 ieee80211_scan_result_list_t *result_list = 1128 1226 &ieee80211_dev->ap_list; … … 1138 1236 if(!str_cmp(ssid, result->scan_result.ssid)) { 1139 1237 result->last_beacon = time(NULL); 1140 fibril_mutex_unlock(scan_mutex);1141 1238 return EOK; 1142 1239 } … … 1145 1242 /* Results are full. */ 1146 1243 if(result_list->size == IEEE80211_MAX_RESULTS_LENGTH - 1) { 1147 fibril_mutex_unlock(scan_mutex);1148 1244 return EOK; 1149 1245 } … … 1183 1279 ap_data->last_beacon = time(NULL); 1184 1280 1281 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex); 1185 1282 ieee80211_scan_result_list_append(result_list, ap_data); 1186 1187 fibril_mutex_unlock(scan_mutex); 1283 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex); 1188 1284 } 1189 1285 … … 1202 1298 ieee80211_mgmt_header_t *mgmt_header) 1203 1299 { 1204 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 1205 1206 ieee80211_dev->current_auth_phase = IEEE80211_AUTH_AUTHENTICATED; 1207 1300 ieee80211_auth_body_t *auth_body = 1301 (ieee80211_auth_body_t *) 1302 ((void *)mgmt_header + sizeof(ieee80211_mgmt_header_t)); 1303 1304 if(auth_body->status != 0) { 1305 ieee80211_set_auth_phase(ieee80211_dev, 1306 IEEE80211_AUTH_DISCONNECTED); 1307 } else { 1308 ieee80211_set_auth_phase(ieee80211_dev, 1309 IEEE80211_AUTH_AUTHENTICATED); 1310 } 1311 1312 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 1208 1313 fibril_condvar_signal(&ieee80211_dev->gen_cond); 1209 1314 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); … … 1223 1328 ieee80211_mgmt_header_t *mgmt_header) 1224 1329 { 1225 ieee80211_scan_result_t *auth_data =1226 &ieee80211_dev->bssid_info.res_link->scan_result;1227 1228 fibril_mutex_lock(&ieee80211_dev->gen_mutex);1229 1230 1330 ieee80211_assoc_resp_body_t *assoc_resp = 1231 1331 (ieee80211_assoc_resp_body_t *) ((void *)mgmt_header + 1232 1332 sizeof(ieee80211_mgmt_header_t)); 1233 1333 1234 ieee80211_dev->bssid_info.aid = uint16_t_le2host(assoc_resp->aid); 1235 memcpy(auth_data->bssid.address, mgmt_header->bssid, ETH_ADDR); 1236 1237 ieee80211_dev->current_auth_phase = IEEE80211_AUTH_ASSOCIATED; 1238 1239 ieee80211_dev->ops->bssid_change(ieee80211_dev); 1240 1334 if(assoc_resp->status != 0) { 1335 ieee80211_set_auth_phase(ieee80211_dev, 1336 IEEE80211_AUTH_DISCONNECTED); 1337 } else { 1338 ieee80211_dev->bssid_info.aid = 1339 uint16_t_le2host(assoc_resp->aid); 1340 ieee80211_set_auth_phase(ieee80211_dev, 1341 IEEE80211_AUTH_ASSOCIATED); 1342 ieee80211_dev->ops->bssid_change(ieee80211_dev, true); 1343 } 1344 1345 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 1241 1346 fibril_condvar_signal(&ieee80211_dev->gen_cond); 1242 1347 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); … … 1418 1523 1419 1524 if(handshake_done) { 1420 /* Insert keys into device. */ 1421 1422 /* Pairwise key. */ 1525 /* Insert Pairwise key. */ 1423 1526 ieee80211_key_config_t key_config; 1424 1527 key_config.suite = auth_data->security.pair_alg; … … 1432 1535 &key_config, true); 1433 1536 1434 /* Group key. */1537 /* Insert Group key. */ 1435 1538 key_config.suite = auth_data->security.group_alg; 1436 1539 key_config.flags = -
uspace/lib/ieee80211/src/ieee80211_iface_impl.c
rd7dadcb4 r053fc2b 48 48 * @param results Structure where should be stored scan results. 49 49 * 50 * @return EOK .50 * @return EOK if everything went OK, EREFUSED when device is not ready yet. 51 51 */ 52 52 int ieee80211_get_scan_results_impl(ddf_fun_t *fun, … … 59 59 return EREFUSED; 60 60 61 fibril_mutex_lock(&ieee80211_dev->ap_list.scan_mutex); 62 time_t scan_span = time(NULL) - ieee80211_dev->ap_list.last_scan; 63 fibril_mutex_unlock(&ieee80211_dev->ap_list.scan_mutex); 64 65 if(now || scan_span > MAX_SCAN_SPAN_SEC) { 61 if(now) { 66 62 ieee80211_dev->ops->scan(ieee80211_dev); 67 63 } 68 64 69 fibril_mutex_lock(&ieee80211_dev->ap_list. scan_mutex);65 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex); 70 66 if(results) { 71 67 ieee80211_scan_result_list_t *result_list = … … 82 78 results->length = i; 83 79 } 84 fibril_mutex_unlock(&ieee80211_dev->ap_list. scan_mutex);80 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex); 85 81 86 82 return EOK; … … 103 99 ieee80211_scan_result_link_t *auth_data, char *password) 104 100 { 105 int rc;106 107 101 ieee80211_dev->bssid_info.res_link = auth_data; 108 102 109 103 /* Set channel. */ 110 rc = ieee80211_dev->ops->set_freq(ieee80211_dev,104 int rc = ieee80211_dev->ops->set_freq(ieee80211_dev, 111 105 ieee80211_channel_to_freq(auth_data->scan_result.channel)); 112 106 if(rc != EOK) … … 122 116 if(rc != EOK) 123 117 return rc; 124 if(ieee80211_dev->current_auth_phase != IEEE80211_AUTH_AUTHENTICATED) 118 if(ieee80211_get_auth_phase(ieee80211_dev) != 119 IEEE80211_AUTH_AUTHENTICATED) { 120 ieee80211_set_auth_phase(ieee80211_dev, 121 IEEE80211_AUTH_DISCONNECTED); 125 122 return EINVAL; 123 } 126 124 127 125 /* Try to associate. */ … … 134 132 if(rc != EOK) 135 133 return rc; 136 if(ieee80211_dev->current_auth_phase != IEEE80211_AUTH_ASSOCIATED) 134 if(ieee80211_get_auth_phase(ieee80211_dev) != 135 IEEE80211_AUTH_ASSOCIATED) { 136 ieee80211_set_auth_phase(ieee80211_dev, 137 IEEE80211_AUTH_DISCONNECTED); 137 138 return EINVAL; 139 } 138 140 139 141 /* On open network, we are finished. */ 140 if(auth_data->scan_result.security.type == IEEE80211_SECURITY_OPEN) 141 return EOK; 142 143 /* Otherwise wait for 4-way handshake to complete. */ 144 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 145 rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond, 146 &ieee80211_dev->gen_mutex, 147 HANDSHAKE_TIMEOUT); 148 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 149 if(rc != EOK) 150 return rc; 151 if(ieee80211_dev->current_auth_phase != IEEE80211_AUTH_ASSOCIATED) 152 return EINVAL; 142 if(auth_data->scan_result.security.type != IEEE80211_SECURITY_OPEN) { 143 /* Otherwise wait for 4-way handshake to complete. */ 144 fibril_mutex_lock(&ieee80211_dev->gen_mutex); 145 rc = fibril_condvar_wait_timeout(&ieee80211_dev->gen_cond, 146 &ieee80211_dev->gen_mutex, 147 HANDSHAKE_TIMEOUT); 148 fibril_mutex_unlock(&ieee80211_dev->gen_mutex); 149 if(rc != EOK) { 150 ieee80211_deauthenticate(ieee80211_dev); 151 return rc; 152 } 153 } 154 155 ieee80211_set_auth_phase(ieee80211_dev, IEEE80211_AUTH_CONNECTED); 153 156 154 157 return EOK; … … 163 166 * @return EOK if everything OK, ETIMEOUT when timeout during authenticating, 164 167 * EINVAL when SSID not in scan results list, EPERM when incorrect password 165 * passed .168 * passed, EREFUSED when device is not ready yet. 166 169 */ 167 170 int ieee80211_connect_impl(ddf_fun_t *fun, char *ssid_start, char *password) … … 170 173 assert(password); 171 174 175 int rc; 176 172 177 nic_t *nic_data = nic_get_from_ddf_fun(fun); 173 178 ieee80211_dev_t *ieee80211_dev = nic_get_specific(nic_data); … … 177 182 178 183 if(ieee80211_is_connected(ieee80211_dev)) { 179 intrc = ieee80211_dev->iface->disconnect(fun);184 rc = ieee80211_dev->iface->disconnect(fun); 180 185 if(rc != EOK) 181 186 return rc; 182 187 } 183 188 184 fibril_mutex_lock(&ieee80211_dev->ap_list.scan_mutex); 189 ieee80211_set_connect_request(ieee80211_dev); 190 191 rc = ENOENT; 192 fibril_mutex_lock(&ieee80211_dev->scan_mutex); 193 194 ieee80211_dev->pending_conn_req = false; 185 195 186 196 ieee80211_scan_result_list_foreach(ieee80211_dev->ap_list, result) { … … 188 198 result->scan_result.ssid, 189 199 str_size(ssid_start))) { 190 fibril_mutex_unlock(&ieee80211_dev->ap_list.scan_mutex); 191 return ieee80211_connect_proc(ieee80211_dev, result, 200 rc = ieee80211_connect_proc(ieee80211_dev, result, 192 201 password); 202 break; 193 203 } 194 204 } 195 205 196 fibril_mutex_unlock(&ieee80211_dev-> ap_list.scan_mutex);197 198 return EINVAL;206 fibril_mutex_unlock(&ieee80211_dev->scan_mutex); 207 208 return rc; 199 209 } 200 210 … … 204 214 * @param fun Device function. 205 215 * 206 * @return EOK if everything OK, E INVAL when not connected to any network.216 * @return EOK if everything OK, EREFUSED if device is not ready yet. 207 217 */ 208 218 int ieee80211_disconnect_impl(ddf_fun_t *fun) … … 215 225 216 226 if(!ieee80211_is_connected(ieee80211_dev)) { 217 return E INVAL;227 return EOK; 218 228 } else { 219 return ieee80211_deauthenticate(ieee80211_dev); 229 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex); 230 int rc = ieee80211_deauthenticate(ieee80211_dev); 231 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex); 232 return rc; 220 233 } 221 234 } -
uspace/lib/ieee80211/src/ieee80211_impl.c
rd7dadcb4 r053fc2b 90 90 * @return EOK. 91 91 */ 92 int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev) 92 int ieee80211_bssid_change_impl(ieee80211_dev_t *ieee80211_dev, 93 bool connected) 93 94 { 94 95 return EOK; … … 118 119 int ieee80211_scan_impl(ieee80211_dev_t *ieee80211_dev) 119 120 { 120 if(ieee80211_is_connected(ieee80211_dev)) 121 return EOK; 122 123 fibril_mutex_lock(&ieee80211_dev->ap_list.scan_mutex); 124 125 /* Remove old entries we don't receive beacons from. */ 126 ieee80211_scan_result_list_t *result_list = 127 &ieee80211_dev->ap_list; 128 list_foreach_safe(result_list->list, cur_link, next_link) { 129 ieee80211_scan_result_link_t *cur_result = 130 list_get_instance(cur_link, 131 ieee80211_scan_result_link_t, 132 link); 133 if((time(NULL) - cur_result->last_beacon) > 134 MAX_KEEP_SCAN_SPAN_SEC) { 135 ieee80211_scan_result_list_remove(result_list, 136 cur_result); 121 fibril_mutex_lock(&ieee80211_dev->scan_mutex); 122 123 if(ieee80211_get_auth_phase(ieee80211_dev) == 124 IEEE80211_AUTH_DISCONNECTED) { 125 fibril_mutex_lock(&ieee80211_dev->ap_list.results_mutex); 126 /* Remove old entries we don't receive beacons from. */ 127 ieee80211_scan_result_list_t *result_list = 128 &ieee80211_dev->ap_list; 129 list_foreach_safe(result_list->list, cur_link, next_link) { 130 ieee80211_scan_result_link_t *cur_result = 131 list_get_instance(cur_link, 132 ieee80211_scan_result_link_t, 133 link); 134 if((time(NULL) - cur_result->last_beacon) > 135 MAX_KEEP_SCAN_SPAN_SEC) { 136 ieee80211_scan_result_list_remove(result_list, 137 cur_result); 138 } 137 139 } 138 } 139 140 fibril_mutex_unlock(&ieee80211_dev->ap_list.scan_mutex); 141 142 uint16_t orig_freq = ieee80211_dev->current_freq; 143 144 for(uint16_t freq = IEEE80211_FIRST_FREQ; 145 freq <= IEEE80211_MAX_FREQ; 146 freq += IEEE80211_CHANNEL_GAP) { 147 ieee80211_dev->ops->set_freq(ieee80211_dev, freq); 148 ieee80211_probe_request(ieee80211_dev, NULL); 149 150 /* Wait for probe responses. */ 151 usleep(100000); 152 } 153 154 ieee80211_dev->ops->set_freq(ieee80211_dev, orig_freq); 155 156 fibril_mutex_lock(&ieee80211_dev->ap_list.scan_mutex); 157 time(&ieee80211_dev->ap_list.last_scan); 158 fibril_mutex_unlock(&ieee80211_dev->ap_list.scan_mutex); 140 fibril_mutex_unlock(&ieee80211_dev->ap_list.results_mutex); 141 142 uint16_t orig_freq = ieee80211_dev->current_freq; 143 144 for(uint16_t freq = IEEE80211_FIRST_FREQ; 145 freq <= IEEE80211_MAX_FREQ; 146 freq += IEEE80211_CHANNEL_GAP) { 147 if(ieee80211_pending_connect_request(ieee80211_dev)) { 148 break; 149 } 150 151 ieee80211_dev->ops->set_freq(ieee80211_dev, freq); 152 ieee80211_probe_request(ieee80211_dev, NULL); 153 154 /* Wait for probe responses. */ 155 async_usleep(SCAN_CHANNEL_WAIT_USEC); 156 } 157 158 ieee80211_dev->ops->set_freq(ieee80211_dev, orig_freq); 159 } 160 161 fibril_mutex_unlock(&ieee80211_dev->scan_mutex); 159 162 160 163 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.