Changeset 8a64320e in mainline for uspace/drv/nic/ar9271/ar9271.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/drv/nic/ar9271/ar9271.c
r09044cb r8a64320e 42 42 #include <nic.h> 43 43 #include <macros.h> 44 45 44 #include "ath_usb.h" 46 45 #include "wmi.h" … … 48 47 #include "ar9271.h" 49 48 50 #define NAME "ar9271"51 #define FIRMWARE_FILENAME "/drv/ar9271/ar9271.fw"49 #define NAME "ar9271" 50 #define FIRMWARE_FILENAME "/drv/ar9271/ar9271.fw" 52 51 53 52 const usb_endpoint_description_t usb_ar9271_out_bulk_endpoint_description = { … … 91 90 &usb_ar9271_out_bulk_endpoint_description, 92 91 &usb_ar9271_in_bulk_endpoint_description, 93 94 92 &usb_ar9271_in_int_endpoint_description, 93 &usb_ar9271_out_int_endpoint_description, 95 94 NULL 96 95 }; … … 100 99 101 100 /* IEEE 802.11 callbacks */ 102 static int ar9271_ieee80211_start(ieee80211_dev_t *ieee80211_dev); 103 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev, 104 void *buffer, size_t buffer_size); 105 static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev, 106 uint16_t freq); 107 static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *ieee80211_dev, 108 bool connected); 109 static int ar9271_ieee80211_key_config(ieee80211_dev_t *ieee80211_dev, 110 ieee80211_key_config_t *key_conf, bool insert); 101 static int ar9271_ieee80211_start(ieee80211_dev_t *); 102 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *, void *, size_t); 103 static int ar9271_ieee80211_set_freq(ieee80211_dev_t *, uint16_t); 104 static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *, bool); 105 static int ar9271_ieee80211_key_config(ieee80211_dev_t *, ieee80211_key_config_t *, 106 bool); 111 107 112 108 static driver_ops_t ar9271_driver_ops = { … … 129 125 static ieee80211_iface_t ar9271_ieee80211_iface; 130 126 131 static int ar9271_get_device_info(ddf_fun_t * dev, nic_device_info_t *info);127 static int ar9271_get_device_info(ddf_fun_t *, nic_device_info_t *); 132 128 static int ar9271_get_cable_state(ddf_fun_t *, nic_cable_state_t *); 133 static int ar9271_get_operation_mode(ddf_fun_t *, int *, 134 nic_channel_mode_t *,nic_role_t *);129 static int ar9271_get_operation_mode(ddf_fun_t *, int *, nic_channel_mode_t *, 130 nic_role_t *); 135 131 136 132 static nic_iface_t ar9271_ieee80211_nic_iface = { … … 142 138 static ddf_dev_ops_t ar9271_ieee80211_dev_ops; 143 139 144 /** 145 * Get device information. 140 /** Get device information. 146 141 * 147 142 */ … … 153 148 memset(info, 0, sizeof(nic_device_info_t)); 154 149 155 info->vendor_id = 0x0 CF3;150 info->vendor_id = 0x0cf3; 156 151 info->device_id = 0x9271; 157 152 str_cpy(info->vendor_name, NIC_VENDOR_MAX_LENGTH, … … 163 158 } 164 159 165 /** 166 * Get cable state. 160 /** Get cable state. 167 161 * 168 162 */ … … 174 168 } 175 169 176 /** 177 * Get operation mode of the device. 170 /** Get operation mode of the device. 178 171 * 179 172 */ … … 188 181 } 189 182 190 /** 191 * Set multicast frames acceptance mode. 192 * 193 */ 194 static int ar9271_on_multicast_mode_change(nic_t *nic, 195 nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt) 196 { 197 /* 198 ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) 199 nic_get_specific(nic); 200 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 201 */ 202 183 /** Set multicast frames acceptance mode. 184 * 185 */ 186 static int ar9271_on_multicast_mode_change(nic_t *nic, 187 nic_multicast_mode_t mode, const nic_address_t *addr, size_t addr_cnt) 188 { 203 189 switch (mode) { 204 case NIC_MULTICAST_BLOCKED: 205 /* TODO */ 206 break; 207 case NIC_MULTICAST_LIST: 208 /* TODO */ 209 break; 210 case NIC_MULTICAST_PROMISC: 211 /* TODO */ 212 break; 213 default: 214 return ENOTSUP; 215 } 216 217 return EOK; 218 } 219 220 /** 221 * Set unicast frames acceptance mode. 190 case NIC_MULTICAST_BLOCKED: 191 /* TODO */ 192 break; 193 case NIC_MULTICAST_LIST: 194 /* TODO */ 195 break; 196 case NIC_MULTICAST_PROMISC: 197 /* TODO */ 198 break; 199 default: 200 return ENOTSUP; 201 } 202 203 return EOK; 204 } 205 206 /** Set unicast frames acceptance mode. 222 207 * 223 208 */ … … 225 210 const nic_address_t *addr, size_t addr_cnt) 226 211 { 227 /*228 ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *)229 nic_get_specific(nic);230 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev);231 */232 233 212 switch (mode) { 234 case NIC_UNICAST_BLOCKED: 235 /* TODO */ 236 break; 237 case NIC_UNICAST_DEFAULT: 238 /* TODO */ 239 break; 240 case NIC_UNICAST_LIST: 241 /* TODO */ 242 break; 243 case NIC_UNICAST_PROMISC: 244 /* TODO */ 245 break; 246 default: 247 return ENOTSUP; 248 } 249 250 return EOK; 251 } 252 253 /** 254 * Set broadcast frames acceptance mode. 255 * 256 */ 257 static int ar9271_on_broadcast_mode_change(nic_t *nic, 258 nic_broadcast_mode_t mode) 259 { 260 /* 261 ieee80211_dev_t *ieee80211_dev = (ieee80211_dev_t *) 262 nic_get_specific(nic); 263 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 264 */ 265 213 case NIC_UNICAST_BLOCKED: 214 /* TODO */ 215 break; 216 case NIC_UNICAST_DEFAULT: 217 /* TODO */ 218 break; 219 case NIC_UNICAST_LIST: 220 /* TODO */ 221 break; 222 case NIC_UNICAST_PROMISC: 223 /* TODO */ 224 break; 225 default: 226 return ENOTSUP; 227 } 228 229 return EOK; 230 } 231 232 /** Set broadcast frames acceptance mode. 233 * 234 */ 235 static int ar9271_on_broadcast_mode_change(nic_t *nic, 236 nic_broadcast_mode_t mode) 237 { 266 238 switch (mode) { 267 268 269 270 271 272 273 274 239 case NIC_BROADCAST_BLOCKED: 240 /* TODO */ 241 break; 242 case NIC_BROADCAST_ACCEPTED: 243 /* TODO */ 244 break; 245 default: 246 return ENOTSUP; 275 247 } 276 248 … … 292 264 void *buffer = malloc(buffer_size); 293 265 294 while (true) {266 while (true) { 295 267 size_t transferred_size; 296 if (htc_read_data_message(ar9271->htc_device,297 298 size_t strip_length = 299 300 sizeof(htc_frame_header_t) +301 302 303 if (transferred_size < strip_length)268 if (htc_read_data_message(ar9271->htc_device, 269 buffer, buffer_size, &transferred_size) == EOK) { 270 size_t strip_length = 271 sizeof(ath_usb_data_header_t) + 272 sizeof(htc_frame_header_t) + 273 sizeof(htc_rx_status_t); 274 275 if (transferred_size < strip_length) 304 276 continue; 305 306 ath_usb_data_header_t *data_header = 307 308 277 278 ath_usb_data_header_t *data_header = 279 (ath_usb_data_header_t *) buffer; 280 309 281 /* Invalid packet. */ 310 if (data_header->tag != uint16_t_le2host(RX_TAG))282 if (data_header->tag != uint16_t_le2host(RX_TAG)) 311 283 continue; 312 284 313 285 htc_rx_status_t *rx_status = 314 315 316 286 (htc_rx_status_t *) ((void *) buffer + 287 sizeof(ath_usb_data_header_t) + 288 sizeof(htc_frame_header_t)); 317 289 318 290 uint16_t data_length = 319 320 321 int16_t payload_length = 322 323 324 if (payload_length - data_length < 0)291 uint16_t_be2host(rx_status->data_length); 292 293 int16_t payload_length = 294 transferred_size - strip_length; 295 296 if (payload_length - data_length < 0) 325 297 continue; 326 298 327 if (ar9271_rx_status_error(rx_status->status))299 if (ar9271_rx_status_error(rx_status->status)) 328 300 continue; 329 301 330 302 void *strip_buffer = buffer + strip_length; 331 303 332 304 ieee80211_rx_handler(ar9271->ieee80211_dev, 333 334 305 strip_buffer, 306 payload_length); 335 307 } 336 308 } … … 341 313 } 342 314 343 /** 344 * IEEE 802.11 handlers. 345 */ 346 315 /** IEEE 802.11 handlers. 316 * 317 */ 347 318 static int ar9271_ieee80211_set_freq(ieee80211_dev_t *ieee80211_dev, 348 319 uint16_t freq) 349 320 { 350 321 assert(ieee80211_dev); … … 357 328 358 329 int rc = hw_freq_switch(ar9271, freq); 359 if (rc != EOK) {330 if (rc != EOK) { 360 331 usb_log_error("Failed to HW switch frequency.\n"); 361 332 return rc; … … 365 336 366 337 rc = hw_rx_init(ar9271); 367 if (rc != EOK) {338 if (rc != EOK) { 368 339 usb_log_error("Failed to initialize RX.\n"); 369 340 return rc; … … 371 342 372 343 uint16_t htc_mode = host2uint16_t_be(1); 373 wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 374 344 wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 345 (uint8_t *) &htc_mode, sizeof(htc_mode), NULL); 375 346 wmi_send_command(ar9271->htc_device, WMI_ENABLE_INTR, NULL, 0, NULL); 376 347 … … 379 350 380 351 static int ar9271_ieee80211_bssid_change(ieee80211_dev_t *ieee80211_dev, 381 352 bool connected) 382 353 { 383 354 assert(ieee80211_dev); 384 355 385 356 ar9271_t *ar9271 = (ar9271_t *) ieee80211_get_specific(ieee80211_dev); 386 387 if (connected) {357 358 if (connected) { 388 359 nic_address_t bssid; 389 360 ieee80211_query_bssid(ieee80211_dev, &bssid); 390 361 391 362 htc_sta_msg_t sta_msg; 392 363 memset(&sta_msg, 0, sizeof(htc_sta_msg_t)); 393 364 sta_msg.is_vif_sta = 0; 394 sta_msg.max_ampdu = 395 365 sta_msg.max_ampdu = 366 host2uint16_t_be(1 << IEEE80211_MAX_AMPDU_FACTOR); 396 367 sta_msg.sta_index = 1; 397 368 sta_msg.vif_index = 0; 398 369 memcpy(&sta_msg.addr, bssid.address, ETH_ADDR); 399 400 wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE, 401 402 370 371 wmi_send_command(ar9271->htc_device, WMI_NODE_CREATE, 372 (uint8_t *) &sta_msg, sizeof(sta_msg), NULL); 373 403 374 htc_rate_msg_t rate_msg; 404 375 memset(&rate_msg, 0, sizeof(htc_rate_msg_t)); 405 376 rate_msg.sta_index = 1; 406 377 rate_msg.is_new = 1; 407 rate_msg.legacy_rates_count = 408 ARRAY_SIZE(ieee80211bg_data_rates); 409 memcpy(&rate_msg.legacy_rates, 410 ieee80211bg_data_rates, 411 ARRAY_SIZE(ieee80211bg_data_rates)); 412 413 wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE, 414 (uint8_t *) &rate_msg, sizeof(rate_msg), NULL); 415 378 rate_msg.legacy_rates_count = ARRAY_SIZE(ieee80211bg_data_rates); 379 memcpy(&rate_msg.legacy_rates, 380 ieee80211bg_data_rates, 381 ARRAY_SIZE(ieee80211bg_data_rates)); 382 383 wmi_send_command(ar9271->htc_device, WMI_RC_RATE_UPDATE, 384 (uint8_t *) &rate_msg, sizeof(rate_msg), NULL); 385 416 386 hw_set_rx_filter(ar9271, true); 417 387 } else { 418 388 uint8_t station_id = 1; 419 389 wmi_send_command(ar9271->htc_device, WMI_NODE_REMOVE, 420 390 &station_id, sizeof(station_id), NULL); 421 391 422 392 hw_set_rx_filter(ar9271, false); … … 429 399 430 400 static int ar9271_ieee80211_key_config(ieee80211_dev_t *ieee80211_dev, 431 401 ieee80211_key_config_t *key_conf, bool insert) 432 402 { 433 403 assert(ieee80211_dev); … … 446 416 ieee80211_query_bssid(ieee80211_dev, &bssid); 447 417 448 switch (key_conf->suite) {449 450 451 452 453 454 455 456 457 458 459 460 461 462 418 switch (key_conf->suite) { 419 case IEEE80211_SECURITY_SUITE_WEP40: 420 key_type = AR9271_KEY_TABLE_TYPE_WEP40; 421 break; 422 case IEEE80211_SECURITY_SUITE_WEP104: 423 key_type = AR9271_KEY_TABLE_TYPE_WEP104; 424 break; 425 case IEEE80211_SECURITY_SUITE_TKIP: 426 key_type = AR9271_KEY_TABLE_TYPE_TKIP; 427 break; 428 case IEEE80211_SECURITY_SUITE_CCMP: 429 key_type = AR9271_KEY_TABLE_TYPE_CCMP; 430 break; 431 default: 432 key_type = -1; 463 433 } 464 434 465 uint8_t key_id = 466 467 435 uint8_t key_id = 436 (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) ? 437 AR9271_STA_KEY_INDEX : key_conf->id; 468 438 469 439 reg_ptr = AR9271_KEY_TABLE(key_id); … … 471 441 data_start = (void *) key_conf->data; 472 442 473 key[0] = uint32_t_le2host( 474 *((uint32_t *) data_start)); 475 key[1] = uint16_t_le2host( 476 *((uint16_t *) (data_start + 4))); 477 key[2] = uint32_t_le2host( 478 *((uint32_t *) (data_start + 6))); 479 key[3] = uint16_t_le2host( 480 *((uint16_t *) (data_start + 10))); 481 key[4] = uint32_t_le2host( 482 *((uint32_t *) (data_start + 12))); 483 484 if(key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40 || 485 key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104) { 443 key[0] = uint32_t_le2host(*((uint32_t *) data_start)); 444 key[1] = uint16_t_le2host(*((uint16_t *) (data_start + 4))); 445 key[2] = uint32_t_le2host(*((uint32_t *) (data_start + 6))); 446 key[3] = uint16_t_le2host(*((uint16_t *) (data_start + 10))); 447 key[4] = uint32_t_le2host(*((uint32_t *) (data_start + 12))); 448 449 if ((key_conf->suite == IEEE80211_SECURITY_SUITE_WEP40) || 450 (key_conf->suite == IEEE80211_SECURITY_SUITE_WEP104)) 486 451 key[4] &= 0xFF; 487 }488 452 489 453 wmi_reg_write(ar9271->htc_device, reg_ptr + 0, key[0]); … … 494 458 wmi_reg_write(ar9271->htc_device, reg_ptr + 20, key_type); 495 459 496 uint32_t macL, macH; 497 if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) { 460 uint32_t macl; 461 uint32_t mach; 462 if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_PAIRWISE) { 498 463 data_start = (void *) bssid.address; 499 macL = uint32_t_le2host(*((uint32_t *) data_start)); 500 macH = uint16_t_le2host(*((uint16_t *) 501 (data_start + 4))); 464 macl = uint32_t_le2host(*((uint32_t *) data_start)); 465 mach = uint16_t_le2host(*((uint16_t *) (data_start + 4))); 502 466 } else { 503 macL = macH = 0; 467 macl = 0; 468 mach = 0; 504 469 } 505 470 506 mac L>>= 1;507 mac L |= (macH& 1) << 31;508 mac H>>= 1;509 mac H|= 0x8000;510 511 wmi_reg_write(ar9271->htc_device, reg_ptr + 24, mac L);512 wmi_reg_write(ar9271->htc_device, reg_ptr + 28, mac H);471 macl >>= 1; 472 macl |= (mach & 1) << 31; 473 mach >>= 1; 474 mach |= 0x8000; 475 476 wmi_reg_write(ar9271->htc_device, reg_ptr + 24, macl); 477 wmi_reg_write(ar9271->htc_device, reg_ptr + 28, mach); 513 478 514 479 /* Setup MIC keys for TKIP. */ 515 if (key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) {480 if (key_conf->suite == IEEE80211_SECURITY_SUITE_TKIP) { 516 481 uint32_t mic[5]; 517 uint8_t *gen_mic = 518 data_start + IEEE80211_TKIP_RX_MIC_OFFSET; 482 uint8_t *gen_mic = data_start + IEEE80211_TKIP_RX_MIC_OFFSET; 519 483 uint8_t *tx_mic; 520 if(key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) { 484 485 if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) 521 486 tx_mic = gen_mic; 522 } else { 523 tx_mic = data_start + 524 IEEE80211_TKIP_TX_MIC_OFFSET; 525 } 526 527 mic[0] = uint32_t_le2host( 528 *((uint32_t *) gen_mic)); 529 mic[1] = uint16_t_le2host( 530 *((uint16_t *) (tx_mic + 2))) & 0xFFFF; 531 mic[2] = uint32_t_le2host( 532 *((uint32_t *) (gen_mic + 4))); 533 mic[3] = uint16_t_le2host( 534 *((uint16_t *) tx_mic)) & 0xFFFF; 535 mic[4] = uint32_t_le2host( 536 *((uint32_t *) (tx_mic + 4))); 537 538 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, 539 mic[0]); 540 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, 541 mic[1]); 542 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 8, 543 mic[2]); 544 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 12, 545 mic[3]); 546 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 16, 547 mic[4]); 548 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20, 549 AR9271_KEY_TABLE_TYPE_CLR); 487 else 488 tx_mic = data_start + IEEE80211_TKIP_TX_MIC_OFFSET; 489 490 mic[0] = uint32_t_le2host(*((uint32_t *) gen_mic)); 491 mic[1] = uint16_t_le2host(*((uint16_t *) (tx_mic + 2))) & 0xFFFF; 492 mic[2] = uint32_t_le2host(*((uint32_t *) (gen_mic + 4))); 493 mic[3] = uint16_t_le2host(*((uint16_t *) tx_mic)) & 0xFFFF; 494 mic[4] = uint32_t_le2host(*((uint32_t *) (tx_mic + 4))); 495 496 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 0, mic[0]); 497 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 4, mic[1]); 498 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 8, mic[2]); 499 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 12, mic[3]); 500 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 16, mic[4]); 501 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 20, 502 AR9271_KEY_TABLE_TYPE_CLR); 550 503 551 504 wmi_reg_write(ar9271->htc_device, mic_reg_ptr + 24, 0); … … 553 506 } 554 507 555 if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP)508 if (key_conf->flags & IEEE80211_KEY_FLAG_TYPE_GROUP) 556 509 ieee80211_setup_key_confirm(ieee80211_dev, true); 557 510 } else { … … 564 517 565 518 static int ar9271_ieee80211_tx_handler(ieee80211_dev_t *ieee80211_dev, 566 519 void *buffer, size_t buffer_size) 567 520 { 568 521 assert(ieee80211_dev); 569 522 570 size_t complete_size, offset; 523 size_t complete_size; 524 size_t offset; 571 525 void *complete_buffer; 572 526 int endpoint; … … 575 529 576 530 uint16_t frame_ctrl = *((uint16_t *) buffer); 577 if (ieee80211_is_data_frame(frame_ctrl)) {531 if (ieee80211_is_data_frame(frame_ctrl)) { 578 532 offset = sizeof(htc_tx_data_header_t) + 579 533 sizeof(htc_frame_header_t); 580 534 complete_size = buffer_size + offset; 581 535 complete_buffer = malloc(complete_size); 582 536 memset(complete_buffer, 0, complete_size); 583 537 584 /* 538 /* 585 539 * Because we handle just station mode yet, node ID and VIF ID 586 540 * are fixed. 587 541 */ 588 542 htc_tx_data_header_t *data_header = 589 (htc_tx_data_header_t *)590 543 (htc_tx_data_header_t *) 544 (complete_buffer + sizeof(htc_frame_header_t)); 591 545 data_header->data_type = HTC_DATA_NORMAL; 592 546 data_header->node_idx = 1; … … 594 548 data_header->cookie = 0; 595 549 596 if (ieee80211_query_using_key(ieee80211_dev)) {550 if (ieee80211_query_using_key(ieee80211_dev)) { 597 551 data_header->keyix = AR9271_STA_KEY_INDEX; 598 int sec_suite = 599 ieee80211_get_pairwise_security(ieee80211_dev); 600 switch(sec_suite) { 601 case IEEE80211_SECURITY_SUITE_WEP40: 602 case IEEE80211_SECURITY_SUITE_WEP104: 603 data_header->key_type = 604 AR9271_KEY_TYPE_WEP; 605 break; 606 case IEEE80211_SECURITY_SUITE_TKIP: 607 data_header->key_type = 608 AR9271_KEY_TYPE_TKIP; 609 break; 610 case IEEE80211_SECURITY_SUITE_CCMP: 611 data_header->key_type = 612 AR9271_KEY_TYPE_AES; 613 break; 552 553 int sec_suite = 554 ieee80211_get_pairwise_security(ieee80211_dev); 555 556 switch (sec_suite) { 557 case IEEE80211_SECURITY_SUITE_WEP40: 558 case IEEE80211_SECURITY_SUITE_WEP104: 559 data_header->key_type = AR9271_KEY_TYPE_WEP; 560 break; 561 case IEEE80211_SECURITY_SUITE_TKIP: 562 data_header->key_type = AR9271_KEY_TYPE_TKIP; 563 break; 564 case IEEE80211_SECURITY_SUITE_CCMP: 565 data_header->key_type = AR9271_KEY_TYPE_AES; 566 break; 614 567 } 615 568 } else { … … 621 574 } else { 622 575 offset = sizeof(htc_tx_management_header_t) + 623 576 sizeof(htc_frame_header_t); 624 577 complete_size = buffer_size + offset; 625 578 complete_buffer = malloc(complete_size); 626 579 memset(complete_buffer, 0, complete_size); 627 580 628 /* 581 /* 629 582 * Because we handle just station mode yet, node ID and VIF ID 630 583 * are fixed. 631 584 */ 632 585 htc_tx_management_header_t *mgmt_header = 633 (htc_tx_management_header_t *)634 586 (htc_tx_management_header_t *) 587 (complete_buffer + sizeof(htc_frame_header_t)); 635 588 mgmt_header->node_idx = 0; 636 589 mgmt_header->vif_idx = 0; … … 645 598 646 599 htc_send_data_message(ar9271->htc_device, complete_buffer, 647 600 complete_size, endpoint); 648 601 649 602 free(complete_buffer); … … 661 614 662 615 int rc = hw_reset(ar9271); 663 if (rc != EOK) {616 if (rc != EOK) { 664 617 usb_log_error("Failed to do HW reset.\n"); 665 618 return rc; … … 667 620 668 621 uint16_t htc_mode = host2uint16_t_be(1); 669 wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 670 622 wmi_send_command(ar9271->htc_device, WMI_SET_MODE, 623 (uint8_t *) &htc_mode, sizeof(htc_mode), NULL); 671 624 wmi_send_command(ar9271->htc_device, WMI_ATH_INIT, NULL, 0, NULL); 672 625 wmi_send_command(ar9271->htc_device, WMI_START_RECV, NULL, 0, NULL); … … 674 627 675 628 rc = hw_rx_init(ar9271); 676 if (rc != EOK) {629 if (rc != EOK) { 677 630 usb_log_error("Failed to initialize RX.\n"); 678 631 return rc; … … 681 634 /* Send capability message to target. */ 682 635 htc_cap_msg_t cap_msg; 683 cap_msg.ampdu_limit = host2uint32_t_be(0x FFFF);684 cap_msg.ampdu_subframes = 0x FF;636 cap_msg.ampdu_limit = host2uint32_t_be(0xffff); 637 cap_msg.ampdu_subframes = 0xff; 685 638 cap_msg.enable_coex = 0; 686 639 cap_msg.tx_chainmask = 0x1; 687 640 688 641 wmi_send_command(ar9271->htc_device, WMI_TARGET_IC_UPDATE, 689 642 (uint8_t *) &cap_msg, sizeof(cap_msg), NULL); 690 643 691 644 rc = htc_init_new_vif(ar9271->htc_device); 692 if (rc != EOK) {645 if (rc != EOK) { 693 646 usb_log_error("Failed to initialize new VIF.\n"); 694 647 return rc; … … 697 650 /* Add data polling fibril. */ 698 651 fid_t fibril = fibril_create(ar9271_data_polling, ar9271); 699 if (fibril == 0) {652 if (fibril == 0) 700 653 return ENOMEM; 701 }654 702 655 fibril_add_ready(fibril); 703 656 … … 725 678 726 679 int rc = ath_usb_init(ar9271->ath_device, usb_device); 727 if (rc != EOK) {680 if (rc != EOK) { 728 681 free(ar9271->ath_device); 729 682 usb_log_error("Failed to initialize ath device.\n"); … … 741 694 742 695 rc = ieee80211_device_init(ar9271->ieee80211_dev, ar9271->ddf_dev); 743 if (rc != EOK) {696 if (rc != EOK) { 744 697 free(ar9271->ieee80211_dev); 745 698 free(ar9271->ath_device); 746 699 usb_log_error("Failed to initialize IEEE80211 device structure." 747 700 "\n"); 748 701 return rc; 749 702 } 750 703 751 704 ieee80211_set_specific(ar9271->ieee80211_dev, ar9271); 752 705 753 706 /* HTC device structure initialization. */ 754 707 ar9271->htc_device = calloc(1, sizeof(htc_device_t)); 755 if (!ar9271->htc_device) {708 if (!ar9271->htc_device) { 756 709 free(ar9271->ieee80211_dev); 757 710 free(ar9271->ath_device); … … 761 714 } 762 715 763 rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev, 764 765 if (rc != EOK) {716 rc = htc_device_init(ar9271->ath_device, ar9271->ieee80211_dev, 717 ar9271->htc_device); 718 if (rc != EOK) { 766 719 free(ar9271->htc_device); 767 720 free(ar9271->ieee80211_dev); … … 774 727 } 775 728 776 /** 777 * Upload firmware to WiFi device. 778 * 729 /** Upload firmware to WiFi device. 730 * 779 731 * @param ar9271 AR9271 device structure 780 * 732 * 781 733 * @return EOK if succeed, negative error code otherwise 734 * 782 735 */ 783 736 static int ar9271_upload_fw(ar9271_t *ar9271) 784 737 { 785 int rc;786 787 738 usb_device_t *usb_device = ar9271->usb_device; 788 789 739 740 /* TODO: Set by maximum packet size in pipe. */ 790 741 static const size_t MAX_TRANSFER_SIZE = 512; 791 742 … … 802 753 803 754 void *fw_data = malloc(file_size); 804 if (fw_data == NULL) {755 if (fw_data == NULL) { 805 756 fclose(fw_file); 806 757 usb_log_error("Failed allocating memory for firmware.\n"); 807 758 return ENOMEM; 808 759 } 809 760 810 761 fread(fw_data, file_size, 1, fw_file); 811 762 fclose(fw_file); … … 816 767 uint8_t *current_data = fw_data; 817 768 uint8_t *buffer = malloc(MAX_TRANSFER_SIZE); 818 while(remain_size > 0) { 769 770 while (remain_size > 0) { 819 771 size_t chunk_size = min(remain_size, MAX_TRANSFER_SIZE); 820 772 memcpy(buffer, current_data, chunk_size); 821 rc = usb_control_request_set(&usb_device->ctrl_pipe,773 int rc = usb_control_request_set(&usb_device->ctrl_pipe, 822 774 USB_REQUEST_TYPE_VENDOR, 823 775 USB_REQUEST_RECIPIENT_DEVICE, … … 825 777 uint16_host2usb(current_addr >> 8), 826 778 0, buffer, chunk_size); 827 if (rc != EOK) {779 if (rc != EOK) { 828 780 free(fw_data); 829 781 free(buffer); … … 841 793 free(buffer); 842 794 843 /* Send command that firmware is successfully uploaded. 844 * This should initiate creating confirmation message in 845 * device side buffer which we will check in htc_check_ready function. 846 */ 847 rc = usb_control_request_set(&usb_device->ctrl_pipe, 795 /* 796 * Send command that firmware is successfully uploaded. 797 * This should initiate creating confirmation message in 798 * device side buffer which we will check in htc_check_ready function. 799 */ 800 int rc = usb_control_request_set(&usb_device->ctrl_pipe, 848 801 USB_REQUEST_TYPE_VENDOR, 849 802 USB_REQUEST_RECIPIENT_DEVICE, … … 852 805 0, NULL, 0); 853 806 854 if (rc != EOK) {807 if (rc != EOK) { 855 808 usb_log_error("IO error when sending fw upload confirmation " 856 809 "message.\n"); 857 810 return rc; 858 811 } … … 867 820 868 821 /** Create driver data structure. 869 * 822 * 870 823 * @param dev The device structure 871 * 824 * 872 825 * @return Intialized device data structure or NULL if error occured 873 826 */ … … 883 836 const char *err_msg = NULL; 884 837 int rc = usb_device_init(usb_device, dev, endpoints, &err_msg); 885 if (rc != EOK) {838 if (rc != EOK) { 886 839 free(usb_device); 887 840 usb_log_error("Failed to create USB device: %s, " … … 902 855 903 856 rc = ar9271_init(ar9271, usb_device); 904 if (rc != EOK) {857 if (rc != EOK) { 905 858 free(ar9271); 906 859 free(usb_device); 907 usb_log_error("Failed to initialize AR9271 structure: %d\n", 908 860 usb_log_error("Failed to initialize AR9271 structure: %d\n", 861 rc); 909 862 return NULL; 910 863 } … … 948 901 /* Initialize AR9271 HTC services. */ 949 902 int rc = htc_init(ar9271->htc_device); 950 if (rc != EOK) {903 if (rc != EOK) { 951 904 ar9271_delete_dev_data(ar9271); 952 905 usb_log_error("HTC initialization failed.\n"); … … 956 909 /* Initialize AR9271 HW. */ 957 910 rc = hw_init(ar9271); 958 if (rc != EOK) {911 if (rc != EOK) { 959 912 ar9271_delete_dev_data(ar9271); 960 913 usb_log_error("HW initialization failed.\n"); … … 964 917 /* Initialize AR9271 IEEE 802.11 framework. */ 965 918 rc = ieee80211_init(ar9271->ieee80211_dev, &ar9271_ieee80211_ops, 966 967 968 if (rc != EOK) {919 &ar9271_ieee80211_iface, &ar9271_ieee80211_nic_iface, 920 &ar9271_ieee80211_dev_ops); 921 if (rc != EOK) { 969 922 ar9271_delete_dev_data(ar9271); 970 923 usb_log_error("Failed to initialize IEEE80211 framework.\n"); … … 973 926 974 927 nic_set_filtering_change_handlers(nic_get_from_ddf_dev(dev), 975 976 928 ar9271_on_unicast_mode_change, ar9271_on_multicast_mode_change, 929 ar9271_on_broadcast_mode_change, NULL, NULL); 977 930 978 931 usb_log_info("HelenOS AR9271 added device.\n"); … … 989 942 990 943 usb_log_info("HelenOS AR9271 driver started.\n"); 991 944 992 945 return ddf_driver_main(&ar9271_driver); 993 946 }
Note:
See TracChangeset
for help on using the changeset viewer.