Merge tag 'staging-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging

Pull staging driver updates from Greg KH:
"Here is the big set of staging driver changes for 6.10-rc1. Not a lot
of cleanups happening this kernel release, intern applications must be
out of sync at the moment. But we did delete two drivers, wlan-ng and
pi433, as they are no longer in use and the developers involved wanted
them just gone entirely, allowing us to drop 19k lines from the tree.

Other than the normal coding style cleanups here, there has been a lot
of work on the vc04_services code, with the intent to finally get that
out of staging hopefully soon. It's getting closer, which is nice to
see.

All of these have been in linux-next for a while with no reported
issues"

* tag 'staging-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging: (98 commits)
staging: pi433: Remove unused driver
staging: vchiq_core: Add missing blank lines
staging: vchiq_core: Drop unnecessary blank lines
staging: vchiq_core: Add parentheses to VCHIQ_MSG_SRCPORT
staging: vchiq_core: Use printk messages for devices
staging: vchiq_arm: Drop unnecessary NULL check
staging: vc04_services: Delete unnecessary NULL check
staging: vc04_services: vchiq_arm: Fix NULL ptr dereferences
Staging: rtl8192e: Rename variable DssCCk
Staging: rtl8192e: Rename variable ExtHTCapInfo
Staging: rtl8192e: Rename variable MPDUDensity
Staging: rtl8192e: Rename variable MaxRxAMPDUFactor
Staging: rtl8192e: Rename variable MaxAMSDUSize
Staging: rtl8192e: Rename variable DelayBA
Staging: rtl8192e: Rename variable RxSTBC
Staging: rtl8192e: Rename variable TxSTBC
Staging: rtl8192e: Rename variable GreenField
Staging: rtl8192e: Rename variable ShortGI20Mhz
Staging: rtl8192e: Rename variable ShortGI40Mhz
Staging: rtl8192e: Rename variable MimoPwrSave
...

+530 -19330
+1 -1
MAINTAINERS
··· 21241 21241 F: drivers/staging/sm750fb/ 21242 21242 21243 21243 STAGING - VIA VT665X DRIVERS 21244 - M: Forest Bond <forest@alittletooquiet.net> 21244 + M: Philipp Hortmann <philipp.g.hortmann@gmail.com> 21245 21245 S: Odd Fixes 21246 21246 F: drivers/staging/vt665?/ 21247 21247
-4
drivers/staging/Kconfig
··· 24 24 25 25 if STAGING 26 26 27 - source "drivers/staging/wlan-ng/Kconfig" 28 - 29 27 source "drivers/staging/olpc_dcon/Kconfig" 30 28 31 29 source "drivers/staging/rtl8192e/Kconfig" ··· 59 61 source "drivers/staging/greybus/Kconfig" 60 62 61 63 source "drivers/staging/vc04_services/Kconfig" 62 - 63 - source "drivers/staging/pi433/Kconfig" 64 64 65 65 source "drivers/staging/axis-fifo/Kconfig" 66 66
-2
drivers/staging/Makefile
··· 2 2 # Makefile for staging directory 3 3 4 4 obj-y += media/ 5 - obj-$(CONFIG_PRISM2_USB) += wlan-ng/ 6 5 obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/ 7 6 obj-$(CONFIG_RTL8192E) += rtl8192e/ 8 7 obj-$(CONFIG_RTL8723BS) += rtl8723bs/ ··· 20 21 obj-$(CONFIG_KS7010) += ks7010/ 21 22 obj-$(CONFIG_GREYBUS) += greybus/ 22 23 obj-$(CONFIG_BCM2835_VCHIQ) += vc04_services/ 23 - obj-$(CONFIG_PI433) += pi433/ 24 24 obj-$(CONFIG_XIL_AXIS_FIFO) += axis-fifo/ 25 25 obj-$(CONFIG_FIELDBUS_DEV) += fieldbus/
+5 -5
drivers/staging/axis-fifo/axis-fifo.c
··· 376 376 */ 377 377 mutex_lock(&fifo->read_lock); 378 378 ret = wait_event_interruptible_timeout(fifo->read_queue, 379 - ioread32(fifo->base_addr + XLLF_RDFO_OFFSET), 380 - read_timeout); 379 + ioread32(fifo->base_addr + XLLF_RDFO_OFFSET), 380 + read_timeout); 381 381 382 382 if (ret <= 0) { 383 383 if (ret == 0) { ··· 517 517 */ 518 518 mutex_lock(&fifo->write_lock); 519 519 ret = wait_event_interruptible_timeout(fifo->write_queue, 520 - ioread32(fifo->base_addr + XLLF_TDFV_OFFSET) 521 - >= words_to_write, 522 - write_timeout); 520 + ioread32(fifo->base_addr + XLLF_TDFV_OFFSET) 521 + >= words_to_write, 522 + write_timeout); 523 523 524 524 if (ret <= 0) { 525 525 if (ret == 0) {
+3 -4
drivers/staging/fbtft/fb_seps525.c
··· 16 16 * GNU General Public License for more details. 17 17 */ 18 18 19 - #include <linux/module.h> 20 - #include <linux/kernel.h> 21 - #include <linux/init.h> 22 - #include <linux/gpio.h> 19 + #include <linux/bits.h> 23 20 #include <linux/delay.h> 21 + #include <linux/init.h> 22 + #include <linux/module.h> 24 23 25 24 #include "fbtft.h" 26 25
+1
drivers/staging/greybus/arche-apb-ctrl.c
··· 466 466 { .compatible = "usbffff,2", }, 467 467 { }, 468 468 }; 469 + MODULE_DEVICE_TABLE(of, arche_apb_ctrl_of_match); 469 470 470 471 static struct platform_driver arche_apb_ctrl_device_driver = { 471 472 .probe = arche_apb_ctrl_probe,
+1 -8
drivers/staging/greybus/arche-platform.c
··· 619 619 { .compatible = "google,arche-platform", }, 620 620 { }, 621 621 }; 622 - 623 - static const struct of_device_id arche_combined_id[] = { 624 - /* Use PID/VID of SVC device */ 625 - { .compatible = "google,arche-platform", }, 626 - { .compatible = "usbffff,2", }, 627 - { }, 628 - }; 629 - MODULE_DEVICE_TABLE(of, arche_combined_id); 622 + MODULE_DEVICE_TABLE(of, arche_platform_of_match); 630 623 631 624 static struct platform_driver arche_platform_device_driver = { 632 625 .probe = arche_platform_probe,
+1 -1
drivers/staging/greybus/audio_manager_module.c
··· 144 144 }; 145 145 ATTRIBUTE_GROUPS(gb_audio_module_default); 146 146 147 - static struct kobj_type gb_audio_module_type = { 147 + static const struct kobj_type gb_audio_module_type = { 148 148 .sysfs_ops = &gb_audio_module_sysfs_ops, 149 149 .release = gb_audio_module_release, 150 150 .default_groups = gb_audio_module_default_groups,
+27 -31
drivers/staging/greybus/camera.c
··· 180 180 181 181 #define GB_CAMERA_MAX_SETTINGS_SIZE 8192 182 182 183 - #define gcam_dbg(gcam, format...) dev_dbg(&gcam->bundle->dev, format) 184 - #define gcam_info(gcam, format...) dev_info(&gcam->bundle->dev, format) 185 - #define gcam_err(gcam, format...) dev_err(&gcam->bundle->dev, format) 186 - 187 183 static int gb_camera_operation_sync_flags(struct gb_connection *connection, 188 184 int type, unsigned int flags, 189 185 void *request, size_t request_size, ··· 228 232 229 233 fmt_info = gb_camera_get_format_info(cfg->format); 230 234 if (!fmt_info) { 231 - gcam_err(gcam, "unsupported greybus image format: %d\n", 232 - cfg->format); 235 + dev_err(&gcam->bundle->dev, "unsupported greybus image format: %d\n", 236 + cfg->format); 233 237 return -EIO; 234 238 } 235 239 ··· 237 241 pkt_size = le32_to_cpu(cfg->max_pkt_size); 238 242 239 243 if (pkt_size == 0) { 240 - gcam_err(gcam, 241 - "Stream %u: invalid zero maximum packet size\n", 242 - i); 244 + dev_err(&gcam->bundle->dev, 245 + "Stream %u: invalid zero maximum packet size\n", 246 + i); 243 247 return -EIO; 244 248 } 245 249 } else { 246 250 pkt_size = le16_to_cpu(cfg->width) * fmt_info->bpp / 8; 247 251 248 252 if (pkt_size != le32_to_cpu(cfg->max_pkt_size)) { 249 - gcam_err(gcam, 250 - "Stream %u: maximum packet size mismatch (%u/%u)\n", 251 - i, pkt_size, cfg->max_pkt_size); 253 + dev_err(&gcam->bundle->dev, 254 + "Stream %u: maximum packet size mismatch (%u/%u)\n", 255 + i, pkt_size, cfg->max_pkt_size); 252 256 return -EIO; 253 257 } 254 258 } ··· 271 275 272 276 /* Validate the returned response structure */ 273 277 if (resp->padding[0] || resp->padding[1]) { 274 - gcam_err(gcam, "response padding != 0\n"); 278 + dev_err(&gcam->bundle->dev, "response padding != 0\n"); 275 279 return -EIO; 276 280 } 277 281 278 282 if (resp->num_streams > nstreams) { 279 - gcam_err(gcam, "got #streams %u > request %u\n", 280 - resp->num_streams, nstreams); 283 + dev_err(&gcam->bundle->dev, "got #streams %u > request %u\n", 284 + resp->num_streams, nstreams); 281 285 return -EIO; 282 286 } 283 287 ··· 285 289 struct gb_camera_stream_config_response *cfg = &resp->config[i]; 286 290 287 291 if (cfg->padding) { 288 - gcam_err(gcam, "stream #%u padding != 0\n", i); 292 + dev_err(&gcam->bundle->dev, "stream #%u padding != 0\n", i); 289 293 return -EIO; 290 294 } 291 295 } ··· 336 340 337 341 ret = gb_camera_set_intf_power_mode(gcam, intf->interface_id, hs); 338 342 if (ret < 0) { 339 - gcam_err(gcam, "failed to set module interface to %s (%d)\n", 340 - hs ? "HS" : "PWM", ret); 343 + dev_err(&gcam->bundle->dev, "failed to set module interface to %s (%d)\n", 344 + hs ? "HS" : "PWM", ret); 341 345 return ret; 342 346 } 343 347 344 348 ret = gb_camera_set_intf_power_mode(gcam, svc->ap_intf_id, hs); 345 349 if (ret < 0) { 346 350 gb_camera_set_intf_power_mode(gcam, intf->interface_id, !hs); 347 - gcam_err(gcam, "failed to set AP interface to %s (%d)\n", 348 - hs ? "HS" : "PWM", ret); 351 + dev_err(&gcam->bundle->dev, "failed to set AP interface to %s (%d)\n", 352 + hs ? "HS" : "PWM", ret); 349 353 return ret; 350 354 } 351 355 ··· 431 435 sizeof(csi_cfg), 432 436 GB_APB_REQUEST_CSI_TX_CONTROL, false); 433 437 if (ret < 0) { 434 - gcam_err(gcam, "failed to start the CSI transmitter\n"); 438 + dev_err(&gcam->bundle->dev, "failed to start the CSI transmitter\n"); 435 439 goto error_power; 436 440 } 437 441 ··· 466 470 GB_APB_REQUEST_CSI_TX_CONTROL, false); 467 471 468 472 if (ret < 0) 469 - gcam_err(gcam, "failed to stop the CSI transmitter\n"); 473 + dev_err(&gcam->bundle->dev, "failed to stop the CSI transmitter\n"); 470 474 471 475 /* Set the UniPro link to low speed mode. */ 472 476 gb_camera_set_power_mode(gcam, false); ··· 503 507 NULL, 0, 504 508 (void *)capabilities, size); 505 509 if (ret) 506 - gcam_err(gcam, "failed to retrieve capabilities: %d\n", ret); 510 + dev_err(&gcam->bundle->dev, "failed to retrieve capabilities: %d\n", ret); 507 511 508 512 done: 509 513 mutex_unlock(&gcam->mutex); ··· 719 723 struct gb_message *request; 720 724 721 725 if (op->type != GB_CAMERA_TYPE_METADATA) { 722 - gcam_err(gcam, "Unsupported unsolicited event: %u\n", op->type); 726 + dev_err(&gcam->bundle->dev, "Unsupported unsolicited event: %u\n", op->type); 723 727 return -EINVAL; 724 728 } 725 729 726 730 request = op->request; 727 731 728 732 if (request->payload_size < sizeof(*payload)) { 729 - gcam_err(gcam, "Wrong event size received (%zu < %zu)\n", 730 - request->payload_size, sizeof(*payload)); 733 + dev_err(&gcam->bundle->dev, "Wrong event size received (%zu < %zu)\n", 734 + request->payload_size, sizeof(*payload)); 731 735 return -EINVAL; 732 736 } 733 737 734 738 payload = request->payload; 735 739 736 - gcam_dbg(gcam, "received metadata for request %u, frame %u, stream %u\n", 737 - payload->request_id, payload->frame_number, payload->stream); 740 + dev_dbg(&gcam->bundle->dev, "received metadata for request %u, frame %u, stream %u\n", 741 + payload->request_id, payload->frame_number, payload->stream); 738 742 739 743 return 0; 740 744 } ··· 1343 1347 1344 1348 ret = gb_connection_enable(gcam->connection); 1345 1349 if (ret) { 1346 - gcam_err(gcam, "failed to enable connection: %d\n", ret); 1350 + dev_err(&gcam->bundle->dev, "failed to enable connection: %d\n", ret); 1347 1351 return ret; 1348 1352 } 1349 1353 1350 1354 if (gcam->data_connection) { 1351 1355 ret = gb_connection_enable(gcam->data_connection); 1352 1356 if (ret) { 1353 - gcam_err(gcam, 1354 - "failed to enable data connection: %d\n", ret); 1357 + dev_err(&gcam->bundle->dev, 1358 + "failed to enable data connection: %d\n", ret); 1355 1359 return ret; 1356 1360 } 1357 1361 }
+5 -7
drivers/staging/greybus/fw-management.c
··· 123 123 fw_info->major = le16_to_cpu(response.major); 124 124 fw_info->minor = le16_to_cpu(response.minor); 125 125 126 - strncpy(fw_info->firmware_tag, response.firmware_tag, 127 - GB_FIRMWARE_TAG_MAX_SIZE); 126 + strscpy_pad(fw_info->firmware_tag, response.firmware_tag); 128 127 129 128 /* 130 129 * The firmware-tag should be NULL terminated, otherwise throw error but ··· 152 153 } 153 154 154 155 request.load_method = load_method; 155 - strncpy(request.firmware_tag, tag, GB_FIRMWARE_TAG_MAX_SIZE); 156 + strscpy_pad(request.firmware_tag, tag); 156 157 157 158 /* 158 159 * The firmware-tag should be NULL terminated, otherwise throw error and ··· 248 249 struct gb_fw_mgmt_backend_fw_version_response response; 249 250 int ret; 250 251 251 - strncpy(request.firmware_tag, fw_info->firmware_tag, 252 - GB_FIRMWARE_TAG_MAX_SIZE); 252 + strscpy_pad(request.firmware_tag, fw_info->firmware_tag); 253 253 254 254 /* 255 255 * The firmware-tag should be NULL terminated, otherwise throw error and ··· 301 303 struct gb_fw_mgmt_backend_fw_update_request request; 302 304 int ret; 303 305 304 - strncpy(request.firmware_tag, tag, GB_FIRMWARE_TAG_MAX_SIZE); 306 + ret = strscpy_pad(request.firmware_tag, tag); 305 307 306 308 /* 307 309 * The firmware-tag should be NULL terminated, otherwise throw error and 308 310 * fail. 309 311 */ 310 - if (request.firmware_tag[GB_FIRMWARE_TAG_MAX_SIZE - 1] != '\0') { 312 + if (ret == -E2BIG) { 311 313 dev_err(fw_mgmt->parent, "backend-update: firmware-tag is not NULL terminated\n"); 312 314 return -EINVAL; 313 315 }
+7 -1
drivers/staging/greybus/light.c
··· 142 142 channel = get_channel_from_mode(channel->light, 143 143 GB_CHANNEL_MODE_TORCH); 144 144 145 + if (!channel) 146 + return -EINVAL; 147 + 145 148 /* For not flash we need to convert brightness to intensity */ 146 149 intensity = channel->intensity_uA.min + 147 150 (channel->intensity_uA.step * channel->led->brightness); ··· 531 528 } 532 529 533 530 channel_flash = get_channel_from_mode(light, GB_CHANNEL_MODE_FLASH); 534 - WARN_ON(!channel_flash); 531 + if (!channel_flash) { 532 + dev_err(dev, "failed to get flash channel from mode\n"); 533 + return -EINVAL; 534 + } 535 535 536 536 fled = &channel_flash->fled; 537 537
+1
drivers/staging/greybus/loopback.c
··· 101 101 static struct class loopback_class = { 102 102 .name = "gb_loopback", 103 103 }; 104 + 104 105 static DEFINE_IDA(loopback_ida); 105 106 106 107 /* Min/max values in jiffies */
+1 -1
drivers/staging/ks7010/ks7010_sdio.c
··· 1136 1136 .remove = ks7010_sdio_remove, 1137 1137 }; 1138 1138 1139 - module_driver(ks7010_sdio_driver, sdio_register_driver, sdio_unregister_driver); 1139 + module_sdio_driver(ks7010_sdio_driver); 1140 1140 MODULE_AUTHOR("Sang Engineering, Qi-Hardware, KeyStream"); 1141 1141 MODULE_DESCRIPTION("Driver for KeyStream KS7010 based SDIO cards"); 1142 1142 MODULE_LICENSE("GPL v2");
-1
drivers/staging/nvec/TODO
··· 1 1 ToDo list (incomplete, unordered) 2 2 - move the driver to the new i2c slave framework 3 3 - finish suspend/resume support 4 - - fix udelay in the isr 5 4 - add atomic ops in order to fix shutoff/reboot problems
+8 -3
drivers/staging/nvec/nvec.c
··· 300 300 { 301 301 mutex_lock(&nvec->sync_write_mutex); 302 302 303 - *msg = NULL; 303 + if (msg != NULL) 304 + *msg = NULL; 305 + 304 306 nvec->sync_write_pending = (data[1] << 8) + data[0]; 305 307 306 308 if (nvec_write_async(nvec, data, size) < 0) { ··· 322 320 323 321 dev_dbg(nvec->dev, "nvec_sync_write: pong!\n"); 324 322 325 - *msg = nvec->last_sync_msg; 323 + if (msg != NULL) 324 + *msg = nvec->last_sync_msg; 325 + else 326 + nvec_msg_free(nvec, nvec->last_sync_msg); 326 327 327 328 mutex_unlock(&nvec->sync_write_mutex); 328 329 ··· 717 712 * TODO: replace the udelay with a read back after each writel above 718 713 * in order to work around a hardware issue, see i2c-tegra.c 719 714 * 720 - * Unfortunately, this change causes an intialisation issue with the 715 + * Unfortunately, this change causes an initialisation issue with the 721 716 * touchpad, which needs to be fixed first. 722 717 */ 723 718 udelay(100);
+5 -4
drivers/staging/nvec/nvec_kbd.c
··· 148 148 nvec_register_notifier(nvec, &keys_dev.notifier, 0); 149 149 150 150 /* Enable keyboard */ 151 - nvec_write_async(nvec, enable_kbd, 2); 151 + nvec_write_sync(nvec, enable_kbd, 2, NULL); 152 152 153 153 /* configures wake on special keys */ 154 - nvec_write_async(nvec, cnfg_wake, 4); 154 + nvec_write_sync(nvec, cnfg_wake, 4, NULL); 155 + 155 156 /* enable wake key reporting */ 156 - nvec_write_async(nvec, cnfg_wake_key_reporting, 3); 157 + nvec_write_sync(nvec, cnfg_wake_key_reporting, 3, NULL); 157 158 158 159 /* Disable caps lock LED */ 159 - nvec_write_async(nvec, clear_leds, sizeof(clear_leds)); 160 + nvec_write_sync(nvec, clear_leds, sizeof(clear_leds), NULL); 160 161 161 162 return 0; 162 163 }
+21 -10
drivers/staging/nvec/nvec_ps2.c
··· 60 60 nvec_write_async(ps2_dev.nvec, buf, sizeof(buf)); 61 61 } 62 62 63 - static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd) 64 - { 65 - unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 }; 66 - 67 - buf[2] = cmd & 0xff; 68 - 69 - dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd); 70 - return nvec_write_async(ps2_dev.nvec, buf, sizeof(buf)); 71 - } 72 - 73 63 static int nvec_ps2_notifier(struct notifier_block *nb, 74 64 unsigned long event_type, void *data) 75 65 { ··· 86 96 } 87 97 88 98 return NOTIFY_DONE; 99 + } 100 + 101 + static int ps2_sendcommand(struct serio *ser_dev, unsigned char cmd) 102 + { 103 + unsigned char buf[] = { NVEC_PS2, SEND_COMMAND, ENABLE_MOUSE, 1 }; 104 + struct nvec_msg *msg; 105 + int ret; 106 + 107 + buf[2] = cmd & 0xff; 108 + 109 + dev_dbg(&ser_dev->dev, "Sending ps2 cmd %02x\n", cmd); 110 + 111 + ret = nvec_write_sync(ps2_dev.nvec, buf, sizeof(buf), &msg); 112 + if (ret < 0) 113 + return ret; 114 + 115 + nvec_ps2_notifier(NULL, NVEC_PS2, msg->data); 116 + 117 + nvec_msg_free(ps2_dev.nvec, msg); 118 + 119 + return 0; 89 120 } 90 121 91 122 static int nvec_mouse_probe(struct platform_device *pdev)
-48
drivers/staging/pi433/Documentation/devicetree/pi433-overlay.dtso
··· 1 - // Definitions for Pi433 2 - /dts-v1/; 3 - /plugin/; 4 - 5 - / { 6 - compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709"; 7 - }; 8 - 9 - &spi0 { 10 - #address-cells = <1>; 11 - #size-cells = <0>; 12 - status = "okay"; 13 - 14 - spidev@0{ 15 - reg = <0>; 16 - status = "disabled"; 17 - }; 18 - 19 - spidev@1{ 20 - reg = <1>; 21 - status = "disabled"; 22 - }; 23 - }; 24 - 25 - &gpio { 26 - pi433_pins: pi433_pins { 27 - brcm,pins = <7 25 24>; 28 - brcm,function = <0 0 0>; // in in in 29 - }; 30 - }; 31 - 32 - &spi0 { 33 - #address-cells = <1>; 34 - #size-cells = <0>; 35 - status = "okay"; 36 - 37 - pi433: pi433@0 { 38 - compatible = "Smarthome-Wolf,pi433"; 39 - reg = <0>; 40 - spi-max-frequency = <10000000>; 41 - status = "okay"; 42 - 43 - pinctrl-0 = <&pi433_pins>; 44 - DIO0-gpio = <&gpio 24 0>; 45 - DIO1-gpio = <&gpio 25 0>; 46 - DIO2-gpio = <&gpio 7 0>; 47 - }; 48 - };
-62
drivers/staging/pi433/Documentation/devicetree/pi433.txt
··· 1 - * Smarthome-Wolf Pi433 - a 433MHz radio module/shield for Raspberry Pi (see www.pi433.de) 2 - 3 - Required properties: 4 - - compatible: must be "Smarthome-Wolf,pi433" 5 - - reg: chip select of SPI Interface 6 - - DIOx-gpio must be dedicated to the GPIO, connected with DIOx of the RFM69 module 7 - 8 - 9 - Example: 10 - 11 - With the following lines in gpio-section, the gpio pins, connected with pi433 are 12 - reserved/declared. 13 - 14 - &gpio{ 15 - [...] 16 - 17 - pi433_pins: pi433_pins { 18 - brcm,pins = <7 25 24>; 19 - brcm,function = <0 0 0>; // in in in 20 - }; 21 - 22 - [...] 23 - } 24 - 25 - With the following lines in spi section, the device pi433 is declared. 26 - It consists of the three gpio pins and an spi interface (here chip select 0) 27 - 28 - &spi0{ 29 - [...] 30 - 31 - pi433: pi433@0 { 32 - compatible = "Smarthome-Wolf,pi433"; 33 - reg = <0>; /* CE 0 */ 34 - #address-cells = <1>; 35 - #size-cells = <0>; 36 - spi-max-frequency = <10000000>; 37 - 38 - pinctrl-0 = <&pi433_pins>; 39 - DIO0-gpio = <&gpio 24 0>; 40 - DIO1-gpio = <&gpio 25 0>; 41 - DIO2-gpio = <&gpio 7 0>; 42 - }; 43 - } 44 - 45 - 46 - 47 - For Raspbian users only 48 - ======================= 49 - Since Raspbian supports device tree overlays, you may use an overlay instead 50 - of editing your boards device tree. 51 - To use the overlay, you need to compile the file pi433-overlay.dtso which can 52 - be found alongside this documentation. 53 - The file needs to be compiled - either manually or by integration in your kernel 54 - source tree. For a manual compile, you may use a command line like the following: 55 - 'linux/scripts/dtc/dtc -@ -I dts -O dtb -o pi433.dtbo pi433-overlay.dtso' 56 - 57 - For compiling inside of the kernel tree, you need to copy pi433-overlay.dtso to 58 - arch/arm/boot/dts/overlays and you need to add the file to the list of files 59 - in the Makefile over there. Execute 'make dtbs' in kernel tree root to make the 60 - kernel make files compile the device tree overlay for you. 61 - 62 -
-274
drivers/staging/pi433/Documentation/pi433.txt
··· 1 - ===== 2 - Pi433 3 - ===== 4 - 5 - 6 - Introduction 7 - ============ 8 - This driver is for controlling pi433, a radio module for the Raspberry Pi 9 - (www.pi433.de). It supports transmission and reception. It can be opened 10 - by multiple applications for transmission and reception. While transmit 11 - jobs are queued and processed automatically in the background, the first 12 - application asking for reception will block out all other applications 13 - until something gets received terminates the read request. 14 - The driver supports on the fly reloading of the hardware fifo of the rf 15 - chip, thus enabling for much longer telegrams than the hardware fifo size. 16 - 17 - Description of driver operation 18 - =============================== 19 - 20 - a) transmission 21 - 22 - Each transmission can take place with a different configuration of the rf 23 - module. Therefore each application can set its own set of parameters. The driver 24 - takes care, that each transmission takes place with the parameterset of the 25 - application, that requests the transmission. To allow the transmission to take 26 - place in the background, a tx thread is introduced. 27 - The transfer of data from the main thread to the tx thread is realised by a 28 - kfifo. With each write request of an application, the passed in data and the 29 - corresponding parameter set gets written to the kfifo. 30 - On the other "side" of the kfifo, the tx thread continuously checks, whether the 31 - kfifo is empty. If not, it gets one set of config and data from the kfifo. If 32 - there is no receive request or the receiver is still waiting for something in 33 - the air, the rf module is set to standby, the parameters for transmission gets 34 - set, the hardware fifo of the rf chip gets preloaded and the transmission gets 35 - started. Upon hardware fifo threshold interrupt it gets reloaded, thus enabling 36 - much longer telegrams than the hardware fifo size. If the telegram is sent and there 37 - is more data available in the kfifo, the procedure is repeated. If not the 38 - transmission cycle ends. 39 - 40 - b) reception 41 - 42 - Since there is only one application allowed to receive data at a time, for 43 - reception there is only one configuration set. 44 - As soon as an application sets a request for receiving a telegram, the reception 45 - configuration set is written to the rf module and it gets set into receiving mode. 46 - Now the driver is waiting, that a predefined RSSI level (signal strength at the 47 - receiver) is reached. Until this hasn't happened, the reception can be 48 - interrupted by the transmission thread at any time to insert a transmission cycle. 49 - As soon as the predefined RSSI level is met, a receiving cycle starts. Similar 50 - as described for the transmission cycle the read out of the hardware fifo is done 51 - dynamically. Upon each hardware fifo threshold interrupt, a portion of data gets 52 - read. So also for reception it is possible to receive more data than the hardware 53 - fifo can hold. 54 - 55 - 56 - Driver API 57 - ========== 58 - 59 - The driver is currently implemented as a character device. Therefore it supports 60 - the calls open, ioctl, read, write and close. 61 - 62 - 63 - params for ioctl 64 - ---------------- 65 - 66 - There are four options: 67 - PI433_IOC_RD_TX_CFG - get the transmission parameters from the driver 68 - PI433_IOC_WR_TX_CFG - set the transmission parameters 69 - PI433_IOC_RD_RX_CFG - get the receiving parameters from the driver 70 - PI433_IOC_WR_RX_CFG - set the receiving parameters 71 - 72 - The tx configuration is transferred via struct pi433_tx_cfg, the parameterset for transmission. 73 - It is divided into two sections: rf parameters and packet format. 74 - 75 - rf params: 76 - frequency 77 - frequency used for transmission. 78 - Allowed values: 433050000...434790000 79 - bit_rate 80 - bit rate used for transmission. 81 - Allowed values: ##### 82 - dev_frequency 83 - frequency deviation in case of FSK. 84 - Allowed values: 600...500000 85 - modulation 86 - FSK - frequency shift key 87 - OOK - On-Off-key 88 - modShaping 89 - shapingOff - no shaping 90 - shaping1_0 - gauss filter with BT 1 (FSK only) 91 - shaping0_5 - gauss filter with BT 0.5 (FSK only) 92 - shaping0_3 - gauss filter with BT 0.3 (FSK only) 93 - shapingBR - filter cut off at BR (OOK only) 94 - shaping2BR - filter cut off at 2*BR (OOK only) 95 - pa_ramp (FSK only) 96 - ramp3400 - amp ramps up in 3.4ms 97 - ramp2000 - amp ramps up in 2.0ms 98 - ramp1000 - amp ramps up in 1ms 99 - ramp500 - amp ramps up in 500us 100 - ramp250 - amp ramps up in 250us 101 - ramp125 - amp ramps up in 125us 102 - ramp100 - amp ramps up in 100us 103 - ramp62 - amp ramps up in 62us 104 - ramp50 - amp ramps up in 50us 105 - ramp40 - amp ramps up in 40us 106 - ramp31 - amp ramps up in 31us 107 - ramp25 - amp ramps up in 25us 108 - ramp20 - amp ramps up in 20us 109 - ramp15 - amp ramps up in 15us 110 - ramp12 - amp ramps up in 12us 111 - ramp10 - amp ramps up in 10us 112 - tx_start_condition 113 - fifo_level - transmission starts, if fifo is filled to 114 - threshold level 115 - fifo_not_empty - transmission starts, as soon as there is one 116 - byte in internal fifo 117 - repetitions 118 - This gives the option, to send a telegram multiple times. Default: 1 119 - 120 - packet format: 121 - enable_preamble 122 - optionOn - a preamble will be automatically generated 123 - optionOff - no preamble will be generated 124 - enable_sync 125 - optionOn - a sync word will be automatically added to 126 - the telegram after the preamble 127 - optionOff - no sync word will be added 128 - Attention: While possible to generate sync without preamble, the 129 - receiver won't be able to detect the sync without preamble. 130 - enable_length_byte 131 - optionOn - the length of the telegram will be automatically 132 - added to the telegram. It's part of the payload 133 - optionOff - no length information will be automatically added 134 - to the telegram. 135 - Attention: For telegram length over 255 bytes, this option can't be used 136 - Attention: should be used in combination with sync, only 137 - enable_address_byte 138 - optionOn - the address byte will be automatically added to the 139 - telegram. It's part of the payload 140 - optionOff - the address byte will not be added to the telegram. 141 - The address byte can be used for address filtering, so the receiver 142 - will only receive telegrams with a given address byte. 143 - Attention: should be used in combination with sync, only 144 - enable_crc 145 - optionOn - an crc will be automatically calculated over the 146 - payload of the telegram and added to the telegram 147 - after payload. 148 - optionOff - no crc will be calculated 149 - preamble_length 150 - length of the preamble. Allowed values: 0...65536 151 - sync_length 152 - length of the sync word. Allowed values: 0...8 153 - fixed_message_length 154 - length of the payload of the telegram. Will override the length 155 - given by the buffer, passed in with the write command. Will be 156 - ignored if set to zero. 157 - sync_pattern[8] 158 - contains up to eight values, that are used as the sync pattern 159 - on sync option 160 - address_byte 161 - one byte, used as address byte on address byte option. 162 - 163 - 164 - The rx configuration is transferred via struct pi433_rx_cfg, the parameterset for receiving. It is divided into two sections: rf parameters and packet format. 165 - 166 - rf params: 167 - frequency 168 - frequency used for transmission. 169 - Allowed values: 433050000...434790000 170 - bit_rate 171 - bit rate used for transmission. 172 - Allowed values: ##### 173 - dev_frequency 174 - frequency deviation in case of FSK. 175 - Allowed values: 600...500000 176 - modulation 177 - FSK - frequency shift key 178 - OOK - on off key 179 - rssi_threshold 180 - threshold value for the signal strength on the receiver input. 181 - If this value is exceeded, a reception cycle starts 182 - Allowed values: 0...255 183 - threshold_decrement 184 - in order to adapt to different levels of singnal strength, over 185 - time the receiver gets more and more sensitive. This value 186 - determs, how fast the sensitivity increases. 187 - step_0_5db - increase in 0,5dB steps 188 - step_1_0db - increase in 1 db steps 189 - step_1_5db - increase in 1,5dB steps 190 - step_2_0db - increase in 2 db steps 191 - step_3_0db - increase in 3 db steps 192 - step_4_0db - increase in 4 db steps 193 - step_5_0db - increase in 5 db steps 194 - step_6_0db - increase in 6 db steps 195 - antenna_impedance 196 - sets the electrical adoption of the antenna 197 - fifty_ohm - for antennas with an impedance of 50Ohm 198 - two_hundred_ohm - for antennas with an impedance of 200Ohm 199 - lna_gain 200 - sets the gain of the low noise amp 201 - automatic - lna gain is determined by an agc 202 - max - lna gain is set to maximum 203 - max_minus_6 - lna gain is set to 6db below max 204 - max_minus_12 - lna gain is set to 12db below max 205 - max_minus_24 - lna gain is set to 24db below max 206 - max_minus_36 - lna gain is set to 36db below max 207 - max_minus_48 - lna gain is set to 48db below max 208 - bw_mantisse 209 - sets the bandwidth of the channel filter - part one: mantisse. 210 - mantisse16 - mantisse is set to 16 211 - mantisse20 - mantisse is set to 20 212 - mantisse24 - mantisse is set to 24 213 - bw_exponent 214 - sets the bandwidth of the channel filter - part two: exponent. 215 - Allowd values: 0...7 216 - dagc; 217 - operation mode of the digital automatic gain control 218 - normal_mode 219 - improve 220 - improve_for_low_modulation_index 221 - 222 - packet format: 223 - enable_sync 224 - optionOn - sync detection is enabled. If configured sync pattern 225 - isn't found, telegram will be internally discarded 226 - optionOff - sync detection is disabled. 227 - enable_length_byte 228 - optionOn - First byte of payload will be used as a length byte, 229 - regardless of the amount of bytes that were requested 230 - by the read request. 231 - optionOff - Number of bytes to be read will be set according to 232 - amount of bytes that were requested by the read request. 233 - Attention: should be used in combination with sync, only 234 - enable_address_filtering; 235 - filtering_off - no address filtering will take place 236 - node_address - all telegrams, not matching the node 237 - address will be internally discarded 238 - node_or_broadcast_address - all telegrams, neither matching the 239 - node, nor the broadcast address will 240 - be internally discarded 241 - Attention: Sync option must be enabled in order to use this feature 242 - enable_crc 243 - optionOn - a crc will be calculated over the payload of 244 - the telegram, that was received. If the 245 - calculated crc doesn't match to two bytes, 246 - that follow the payload, the telegram will be 247 - internally discarded. 248 - Attention: This option is only operational if sync on and fixed length 249 - or length byte is used 250 - sync_length 251 - Gives the length of the payload. 252 - Attention: This setting must meet the setting of the transmitter, 253 - if sync option is used. 254 - fixed_message_length 255 - Overrides the telegram length either given by the first byte of 256 - payload or by the read request. 257 - bytes_to_drop 258 - gives the number of bytes, that will be dropped before transferring 259 - data to the read buffer 260 - This option is only useful if all packet helper are switched 261 - off and the rf chip is used in raw receiving mode. This may be 262 - needed, if a telegram of a third party device should be received, 263 - using a protocol not compatible with the packet engine of the rf69 chip. 264 - sync_pattern[8] 265 - contains up to eight values, that are used as the sync pattern 266 - on sync option. 267 - This setting must meet the configuration of the transmitting device, 268 - if sync option is enabled. 269 - node_address 270 - one byte, used as node address byte on address byte option. 271 - broadcast_address 272 - one byte, used as broadcast address byte on address byte option. 273 - 274 -
-17
drivers/staging/pi433/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - config PI433 3 - tristate "Pi433 - a 433MHz radio module for Raspberry Pi" 4 - depends on SPI 5 - help 6 - This option allows you to enable support for the radio module Pi433. 7 - 8 - Pi433 is a shield that fits onto the GPIO header of a Raspberry Pi 9 - or compatible. It extends the Raspberry Pi with the option, to 10 - send and receive data in the 433MHz ISM band - for example to 11 - communicate between two systems without using ethernet or bluetooth 12 - or for control or read sockets, actors, sensors, widely available 13 - for low price. 14 - 15 - For details or the option to buy, please visit https://pi433.de/en.html 16 - 17 - If in doubt, say N here, but saying yes most probably won't hurt
-4
drivers/staging/pi433/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - obj-$(CONFIG_PI433) += pi433.o 3 - 4 - pi433-objs := pi433_if.o rf69.o
-8
drivers/staging/pi433/TODO
··· 1 - * currently the code introduces new IOCTLs. I'm afraid this is a bad idea. 2 - -> Replace this with another interface, hints are welcome! 3 - * Some missing data (marked with ###) needs to be added in the documentation 4 - * Change (struct pi433_tx_cfg)->bit_rate to be a u32 so that we can support 5 - bit rates up to 300kbps per the spec. 6 - -> This configuration needs to be moved to sysfs instead of being done through 7 - IOCTL. Going forward, we need to port userspace tools to use sysfs instead 8 - of IOCTL and then we would delete IOCTL.
-1438
drivers/staging/pi433/pi433_if.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * userspace interface for pi433 radio module 4 - * 5 - * Pi433 is a 433MHz radio module for the Raspberry Pi. 6 - * It is based on the HopeRf Module RFM69CW. Therefore inside of this 7 - * driver, you'll find an abstraction of the rf69 chip. 8 - * 9 - * If needed, this driver could be extended, to also support other 10 - * devices, basing on HopeRfs rf69. 11 - * 12 - * The driver can also be extended, to support other modules of 13 - * HopeRf with a similar interace - e. g. RFM69HCW, RFM12, RFM95, ... 14 - * 15 - * Copyright (C) 2016 Wolf-Entwicklungen 16 - * Marcus Wolf <linux@wolf-entwicklungen.de> 17 - */ 18 - 19 - #undef DEBUG 20 - 21 - #include <linux/init.h> 22 - #include <linux/module.h> 23 - #include <linux/idr.h> 24 - #include <linux/ioctl.h> 25 - #include <linux/uaccess.h> 26 - #include <linux/fs.h> 27 - #include <linux/device.h> 28 - #include <linux/cdev.h> 29 - #include <linux/err.h> 30 - #include <linux/kfifo.h> 31 - #include <linux/errno.h> 32 - #include <linux/mutex.h> 33 - #include <linux/of.h> 34 - #include <linux/interrupt.h> 35 - #include <linux/irq.h> 36 - #include <linux/gpio/consumer.h> 37 - #include <linux/kthread.h> 38 - #include <linux/wait.h> 39 - #include <linux/spi/spi.h> 40 - #ifdef CONFIG_COMPAT 41 - #include <linux/compat.h> 42 - #endif 43 - #include <linux/debugfs.h> 44 - #include <linux/seq_file.h> 45 - 46 - #include "pi433_if.h" 47 - #include "rf69.h" 48 - 49 - #define N_PI433_MINORS BIT(MINORBITS) /*32*/ /* ... up to 256 */ 50 - #define MAX_MSG_SIZE 900 /* min: FIFO_SIZE! */ 51 - #define MSG_FIFO_SIZE 65536 /* 65536 = 2^16 */ 52 - #define FIFO_THRESHOLD 15 /* bytes */ 53 - #define NUM_DIO 2 54 - 55 - static dev_t pi433_dev; 56 - static DEFINE_IDR(pi433_idr); 57 - static DEFINE_MUTEX(minor_lock); /* Protect idr accesses */ 58 - static struct dentry *root_dir; /* debugfs root directory for the driver */ 59 - 60 - /* mainly for udev to create /dev/pi433 */ 61 - static const struct class pi433_class = { 62 - .name = "pi433", 63 - }; 64 - 65 - /* 66 - * tx config is instance specific 67 - * so with each open a new tx config struct is needed 68 - */ 69 - /* 70 - * rx config is device specific 71 - * so we have just one rx config, ebedded in device struct 72 - */ 73 - struct pi433_device { 74 - /* device handling related values */ 75 - dev_t devt; 76 - int minor; 77 - struct device *dev; 78 - struct cdev *cdev; 79 - struct spi_device *spi; 80 - 81 - /* irq related values */ 82 - struct gpio_desc *gpiod[NUM_DIO]; 83 - int irq_num[NUM_DIO]; 84 - u8 irq_state[NUM_DIO]; 85 - 86 - /* tx related values */ 87 - STRUCT_KFIFO_REC_1(MSG_FIFO_SIZE) tx_fifo; 88 - struct mutex tx_fifo_lock; /* serialize userspace writers */ 89 - struct task_struct *tx_task_struct; 90 - wait_queue_head_t tx_wait_queue; 91 - u8 free_in_fifo; 92 - char buffer[MAX_MSG_SIZE]; 93 - 94 - /* rx related values */ 95 - struct pi433_rx_cfg rx_cfg; 96 - u8 *rx_buffer; 97 - unsigned int rx_buffer_size; 98 - u32 rx_bytes_to_drop; 99 - u32 rx_bytes_dropped; 100 - unsigned int rx_position; 101 - struct mutex rx_lock; /* protects rx_* variable accesses */ 102 - wait_queue_head_t rx_wait_queue; 103 - 104 - /* fifo wait queue */ 105 - struct task_struct *fifo_task_struct; 106 - wait_queue_head_t fifo_wait_queue; 107 - 108 - /* flags */ 109 - bool rx_active; 110 - bool tx_active; 111 - bool interrupt_rx_allowed; 112 - }; 113 - 114 - struct pi433_instance { 115 - struct pi433_device *device; 116 - struct pi433_tx_cfg tx_cfg; 117 - 118 - /* control flags */ 119 - bool tx_cfg_initialized; 120 - }; 121 - 122 - /*-------------------------------------------------------------------------*/ 123 - 124 - /* GPIO interrupt handlers */ 125 - static irqreturn_t DIO0_irq_handler(int irq, void *dev_id) 126 - { 127 - struct pi433_device *device = dev_id; 128 - 129 - if (device->irq_state[DIO0] == DIO_PACKET_SENT) { 130 - device->free_in_fifo = FIFO_SIZE; 131 - dev_dbg(device->dev, "DIO0 irq: Packet sent\n"); 132 - wake_up_interruptible(&device->fifo_wait_queue); 133 - } else if (device->irq_state[DIO0] == DIO_RSSI_DIO0) { 134 - dev_dbg(device->dev, "DIO0 irq: RSSI level over threshold\n"); 135 - wake_up_interruptible(&device->rx_wait_queue); 136 - } else if (device->irq_state[DIO0] == DIO_PAYLOAD_READY) { 137 - dev_dbg(device->dev, "DIO0 irq: Payload ready\n"); 138 - device->free_in_fifo = 0; 139 - wake_up_interruptible(&device->fifo_wait_queue); 140 - } 141 - 142 - return IRQ_HANDLED; 143 - } 144 - 145 - static irqreturn_t DIO1_irq_handler(int irq, void *dev_id) 146 - { 147 - struct pi433_device *device = dev_id; 148 - 149 - if (device->irq_state[DIO1] == DIO_FIFO_NOT_EMPTY_DIO1) { 150 - device->free_in_fifo = FIFO_SIZE; 151 - } else if (device->irq_state[DIO1] == DIO_FIFO_LEVEL) { 152 - if (device->rx_active) 153 - device->free_in_fifo = FIFO_THRESHOLD - 1; 154 - else 155 - device->free_in_fifo = FIFO_SIZE - FIFO_THRESHOLD - 1; 156 - } 157 - dev_dbg(device->dev, 158 - "DIO1 irq: %d bytes free in fifo\n", device->free_in_fifo); 159 - wake_up_interruptible(&device->fifo_wait_queue); 160 - 161 - return IRQ_HANDLED; 162 - } 163 - 164 - /*-------------------------------------------------------------------------*/ 165 - 166 - static int 167 - rf69_set_rx_cfg(struct pi433_device *dev, struct pi433_rx_cfg *rx_cfg) 168 - { 169 - int ret; 170 - int payload_length; 171 - 172 - /* receiver config */ 173 - ret = rf69_set_frequency(dev->spi, rx_cfg->frequency); 174 - if (ret < 0) 175 - return ret; 176 - ret = rf69_set_modulation(dev->spi, rx_cfg->modulation); 177 - if (ret < 0) 178 - return ret; 179 - ret = rf69_set_bit_rate(dev->spi, rx_cfg->bit_rate); 180 - if (ret < 0) 181 - return ret; 182 - ret = rf69_set_antenna_impedance(dev->spi, rx_cfg->antenna_impedance); 183 - if (ret < 0) 184 - return ret; 185 - ret = rf69_set_rssi_threshold(dev->spi, rx_cfg->rssi_threshold); 186 - if (ret < 0) 187 - return ret; 188 - ret = rf69_set_ook_threshold_dec(dev->spi, rx_cfg->threshold_decrement); 189 - if (ret < 0) 190 - return ret; 191 - ret = rf69_set_bandwidth(dev->spi, rx_cfg->bw_mantisse, 192 - rx_cfg->bw_exponent); 193 - if (ret < 0) 194 - return ret; 195 - ret = rf69_set_bandwidth_during_afc(dev->spi, rx_cfg->bw_mantisse, 196 - rx_cfg->bw_exponent); 197 - if (ret < 0) 198 - return ret; 199 - ret = rf69_set_dagc(dev->spi, rx_cfg->dagc); 200 - if (ret < 0) 201 - return ret; 202 - 203 - dev->rx_bytes_to_drop = rx_cfg->bytes_to_drop; 204 - 205 - /* packet config */ 206 - /* enable */ 207 - if (rx_cfg->enable_sync == OPTION_ON) { 208 - ret = rf69_enable_sync(dev->spi); 209 - if (ret < 0) 210 - return ret; 211 - 212 - ret = rf69_set_fifo_fill_condition(dev->spi, 213 - after_sync_interrupt); 214 - if (ret < 0) 215 - return ret; 216 - } else { 217 - ret = rf69_disable_sync(dev->spi); 218 - if (ret < 0) 219 - return ret; 220 - 221 - ret = rf69_set_fifo_fill_condition(dev->spi, always); 222 - if (ret < 0) 223 - return ret; 224 - } 225 - if (rx_cfg->enable_length_byte == OPTION_ON) { 226 - ret = rf69_set_packet_format(dev->spi, packet_length_var); 227 - if (ret < 0) 228 - return ret; 229 - } else { 230 - ret = rf69_set_packet_format(dev->spi, packet_length_fix); 231 - if (ret < 0) 232 - return ret; 233 - } 234 - ret = rf69_set_address_filtering(dev->spi, 235 - rx_cfg->enable_address_filtering); 236 - if (ret < 0) 237 - return ret; 238 - 239 - if (rx_cfg->enable_crc == OPTION_ON) { 240 - ret = rf69_enable_crc(dev->spi); 241 - if (ret < 0) 242 - return ret; 243 - } else { 244 - ret = rf69_disable_crc(dev->spi); 245 - if (ret < 0) 246 - return ret; 247 - } 248 - 249 - /* lengths */ 250 - ret = rf69_set_sync_size(dev->spi, rx_cfg->sync_length); 251 - if (ret < 0) 252 - return ret; 253 - if (rx_cfg->enable_length_byte == OPTION_ON) { 254 - ret = rf69_set_payload_length(dev->spi, 0xff); 255 - if (ret < 0) 256 - return ret; 257 - } else if (rx_cfg->fixed_message_length != 0) { 258 - payload_length = rx_cfg->fixed_message_length; 259 - if (rx_cfg->enable_length_byte == OPTION_ON) 260 - payload_length++; 261 - if (rx_cfg->enable_address_filtering != filtering_off) 262 - payload_length++; 263 - ret = rf69_set_payload_length(dev->spi, payload_length); 264 - if (ret < 0) 265 - return ret; 266 - } else { 267 - ret = rf69_set_payload_length(dev->spi, 0); 268 - if (ret < 0) 269 - return ret; 270 - } 271 - 272 - /* values */ 273 - if (rx_cfg->enable_sync == OPTION_ON) { 274 - ret = rf69_set_sync_values(dev->spi, rx_cfg->sync_pattern); 275 - if (ret < 0) 276 - return ret; 277 - } 278 - if (rx_cfg->enable_address_filtering != filtering_off) { 279 - ret = rf69_set_node_address(dev->spi, rx_cfg->node_address); 280 - if (ret < 0) 281 - return ret; 282 - ret = rf69_set_broadcast_address(dev->spi, 283 - rx_cfg->broadcast_address); 284 - if (ret < 0) 285 - return ret; 286 - } 287 - 288 - return 0; 289 - } 290 - 291 - static int 292 - rf69_set_tx_cfg(struct pi433_device *dev, struct pi433_tx_cfg *tx_cfg) 293 - { 294 - int ret; 295 - 296 - ret = rf69_set_frequency(dev->spi, tx_cfg->frequency); 297 - if (ret < 0) 298 - return ret; 299 - ret = rf69_set_modulation(dev->spi, tx_cfg->modulation); 300 - if (ret < 0) 301 - return ret; 302 - ret = rf69_set_bit_rate(dev->spi, tx_cfg->bit_rate); 303 - if (ret < 0) 304 - return ret; 305 - ret = rf69_set_deviation(dev->spi, tx_cfg->dev_frequency); 306 - if (ret < 0) 307 - return ret; 308 - ret = rf69_set_pa_ramp(dev->spi, tx_cfg->pa_ramp); 309 - if (ret < 0) 310 - return ret; 311 - ret = rf69_set_modulation_shaping(dev->spi, tx_cfg->mod_shaping); 312 - if (ret < 0) 313 - return ret; 314 - ret = rf69_set_tx_start_condition(dev->spi, tx_cfg->tx_start_condition); 315 - if (ret < 0) 316 - return ret; 317 - 318 - /* packet format enable */ 319 - if (tx_cfg->enable_preamble == OPTION_ON) { 320 - ret = rf69_set_preamble_length(dev->spi, 321 - tx_cfg->preamble_length); 322 - if (ret < 0) 323 - return ret; 324 - } else { 325 - ret = rf69_set_preamble_length(dev->spi, 0); 326 - if (ret < 0) 327 - return ret; 328 - } 329 - 330 - if (tx_cfg->enable_sync == OPTION_ON) { 331 - ret = rf69_set_sync_size(dev->spi, tx_cfg->sync_length); 332 - if (ret < 0) 333 - return ret; 334 - ret = rf69_set_sync_values(dev->spi, tx_cfg->sync_pattern); 335 - if (ret < 0) 336 - return ret; 337 - ret = rf69_enable_sync(dev->spi); 338 - if (ret < 0) 339 - return ret; 340 - } else { 341 - ret = rf69_disable_sync(dev->spi); 342 - if (ret < 0) 343 - return ret; 344 - } 345 - 346 - if (tx_cfg->enable_length_byte == OPTION_ON) { 347 - ret = rf69_set_packet_format(dev->spi, packet_length_var); 348 - if (ret < 0) 349 - return ret; 350 - } else { 351 - ret = rf69_set_packet_format(dev->spi, packet_length_fix); 352 - if (ret < 0) 353 - return ret; 354 - } 355 - 356 - if (tx_cfg->enable_crc == OPTION_ON) { 357 - ret = rf69_enable_crc(dev->spi); 358 - if (ret < 0) 359 - return ret; 360 - } else { 361 - ret = rf69_disable_crc(dev->spi); 362 - if (ret < 0) 363 - return ret; 364 - } 365 - 366 - return 0; 367 - } 368 - 369 - /*-------------------------------------------------------------------------*/ 370 - 371 - static int pi433_start_rx(struct pi433_device *dev) 372 - { 373 - int retval; 374 - 375 - /* return without action, if no pending read request */ 376 - if (!dev->rx_active) 377 - return 0; 378 - 379 - /* setup for receiving */ 380 - retval = rf69_set_rx_cfg(dev, &dev->rx_cfg); 381 - if (retval) 382 - return retval; 383 - 384 - /* setup rssi irq */ 385 - retval = rf69_set_dio_mapping(dev->spi, DIO0, DIO_RSSI_DIO0); 386 - if (retval < 0) 387 - return retval; 388 - dev->irq_state[DIO0] = DIO_RSSI_DIO0; 389 - irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING); 390 - 391 - /* setup fifo level interrupt */ 392 - retval = rf69_set_fifo_threshold(dev->spi, FIFO_SIZE - FIFO_THRESHOLD); 393 - if (retval < 0) 394 - return retval; 395 - retval = rf69_set_dio_mapping(dev->spi, DIO1, DIO_FIFO_LEVEL); 396 - if (retval < 0) 397 - return retval; 398 - dev->irq_state[DIO1] = DIO_FIFO_LEVEL; 399 - irq_set_irq_type(dev->irq_num[DIO1], IRQ_TYPE_EDGE_RISING); 400 - 401 - /* set module to receiving mode */ 402 - retval = rf69_set_mode(dev->spi, receive); 403 - if (retval < 0) 404 - return retval; 405 - 406 - return 0; 407 - } 408 - 409 - /*-------------------------------------------------------------------------*/ 410 - 411 - static int pi433_receive(void *data) 412 - { 413 - struct pi433_device *dev = data; 414 - struct spi_device *spi = dev->spi; 415 - int bytes_to_read, bytes_total; 416 - int retval; 417 - 418 - dev->interrupt_rx_allowed = false; 419 - 420 - /* wait for any tx to finish */ 421 - dev_dbg(dev->dev, "rx: going to wait for any tx to finish\n"); 422 - retval = wait_event_interruptible(dev->rx_wait_queue, !dev->tx_active); 423 - if (retval) { 424 - /* wait was interrupted */ 425 - dev->interrupt_rx_allowed = true; 426 - wake_up_interruptible(&dev->tx_wait_queue); 427 - return retval; 428 - } 429 - 430 - /* prepare status vars */ 431 - dev->free_in_fifo = FIFO_SIZE; 432 - dev->rx_position = 0; 433 - dev->rx_bytes_dropped = 0; 434 - 435 - /* setup radio module to listen for something "in the air" */ 436 - retval = pi433_start_rx(dev); 437 - if (retval) 438 - return retval; 439 - 440 - /* now check RSSI, if low wait for getting high (RSSI interrupt) */ 441 - while (!(rf69_read_reg(spi, REG_IRQFLAGS1) & MASK_IRQFLAGS1_RSSI)) { 442 - /* allow tx to interrupt us while waiting for high RSSI */ 443 - dev->interrupt_rx_allowed = true; 444 - wake_up_interruptible(&dev->tx_wait_queue); 445 - 446 - /* wait for RSSI level to become high */ 447 - dev_dbg(dev->dev, "rx: going to wait for high RSSI level\n"); 448 - retval = wait_event_interruptible(dev->rx_wait_queue, 449 - rf69_read_reg(spi, REG_IRQFLAGS1) & 450 - MASK_IRQFLAGS1_RSSI); 451 - if (retval) /* wait was interrupted */ 452 - goto abort; 453 - dev->interrupt_rx_allowed = false; 454 - 455 - /* cross check for ongoing tx */ 456 - if (!dev->tx_active) 457 - break; 458 - } 459 - 460 - /* configure payload ready irq */ 461 - retval = rf69_set_dio_mapping(spi, DIO0, DIO_PAYLOAD_READY); 462 - if (retval < 0) 463 - goto abort; 464 - dev->irq_state[DIO0] = DIO_PAYLOAD_READY; 465 - irq_set_irq_type(dev->irq_num[DIO0], IRQ_TYPE_EDGE_RISING); 466 - 467 - /* fixed or unlimited length? */ 468 - if (dev->rx_cfg.fixed_message_length != 0) { 469 - if (dev->rx_cfg.fixed_message_length > dev->rx_buffer_size) { 470 - retval = -1; 471 - goto abort; 472 - } 473 - bytes_total = dev->rx_cfg.fixed_message_length; 474 - dev_dbg(dev->dev, "rx: msg len set to %d by fixed length\n", 475 - bytes_total); 476 - } else { 477 - bytes_total = dev->rx_buffer_size; 478 - dev_dbg(dev->dev, "rx: msg len set to %d as requested by read\n", 479 - bytes_total); 480 - } 481 - 482 - /* length byte enabled? */ 483 - if (dev->rx_cfg.enable_length_byte == OPTION_ON) { 484 - retval = wait_event_interruptible(dev->fifo_wait_queue, 485 - dev->free_in_fifo < FIFO_SIZE); 486 - if (retval) /* wait was interrupted */ 487 - goto abort; 488 - 489 - rf69_read_fifo(spi, (u8 *)&bytes_total, 1); 490 - if (bytes_total > dev->rx_buffer_size) { 491 - retval = -1; 492 - goto abort; 493 - } 494 - dev->free_in_fifo++; 495 - dev_dbg(dev->dev, "rx: msg len reset to %d due to length byte\n", 496 - bytes_total); 497 - } 498 - 499 - /* address byte enabled? */ 500 - if (dev->rx_cfg.enable_address_filtering != filtering_off) { 501 - u8 dummy; 502 - 503 - bytes_total--; 504 - 505 - retval = wait_event_interruptible(dev->fifo_wait_queue, 506 - dev->free_in_fifo < FIFO_SIZE); 507 - if (retval) /* wait was interrupted */ 508 - goto abort; 509 - 510 - rf69_read_fifo(spi, &dummy, 1); 511 - dev->free_in_fifo++; 512 - dev_dbg(dev->dev, "rx: address byte stripped off\n"); 513 - } 514 - 515 - /* get payload */ 516 - while (dev->rx_position < bytes_total) { 517 - if (!(rf69_read_reg(spi, REG_IRQFLAGS2) & MASK_IRQFLAGS2_PAYLOAD_READY)) { 518 - retval = wait_event_interruptible(dev->fifo_wait_queue, 519 - dev->free_in_fifo < FIFO_SIZE); 520 - if (retval) /* wait was interrupted */ 521 - goto abort; 522 - } 523 - 524 - /* need to drop bytes or acquire? */ 525 - if (dev->rx_bytes_to_drop > dev->rx_bytes_dropped) 526 - bytes_to_read = dev->rx_bytes_to_drop - 527 - dev->rx_bytes_dropped; 528 - else 529 - bytes_to_read = bytes_total - dev->rx_position; 530 - 531 - /* access the fifo */ 532 - if (bytes_to_read > FIFO_SIZE - dev->free_in_fifo) 533 - bytes_to_read = FIFO_SIZE - dev->free_in_fifo; 534 - retval = rf69_read_fifo(spi, 535 - &dev->rx_buffer[dev->rx_position], 536 - bytes_to_read); 537 - if (retval) /* read failed */ 538 - goto abort; 539 - 540 - dev->free_in_fifo += bytes_to_read; 541 - 542 - /* adjust status vars */ 543 - if (dev->rx_bytes_to_drop > dev->rx_bytes_dropped) 544 - dev->rx_bytes_dropped += bytes_to_read; 545 - else 546 - dev->rx_position += bytes_to_read; 547 - } 548 - 549 - /* rx done, wait was interrupted or error occurred */ 550 - abort: 551 - dev->interrupt_rx_allowed = true; 552 - if (rf69_set_mode(dev->spi, standby)) 553 - pr_err("rf69_set_mode(): radio module failed to go standby\n"); 554 - wake_up_interruptible(&dev->tx_wait_queue); 555 - 556 - if (retval) 557 - return retval; 558 - else 559 - return bytes_total; 560 - } 561 - 562 - static int pi433_tx_thread(void *data) 563 - { 564 - struct pi433_device *device = data; 565 - struct spi_device *spi = device->spi; 566 - struct pi433_tx_cfg tx_cfg; 567 - size_t size; 568 - bool rx_interrupted = false; 569 - int position, repetitions; 570 - int retval; 571 - 572 - while (1) { 573 - /* wait for fifo to be populated or for request to terminate*/ 574 - dev_dbg(device->dev, "thread: going to wait for new messages\n"); 575 - wait_event_interruptible(device->tx_wait_queue, 576 - (!kfifo_is_empty(&device->tx_fifo) || 577 - kthread_should_stop())); 578 - if (kthread_should_stop()) 579 - return 0; 580 - 581 - /* 582 - * get data from fifo in the following order: 583 - * - tx_cfg 584 - * - size of message 585 - * - message 586 - */ 587 - retval = kfifo_out(&device->tx_fifo, &tx_cfg, sizeof(tx_cfg)); 588 - if (retval != sizeof(tx_cfg)) { 589 - dev_dbg(device->dev, 590 - "reading tx_cfg from fifo failed: got %d byte(s), expected %d\n", 591 - retval, (unsigned int)sizeof(tx_cfg)); 592 - continue; 593 - } 594 - 595 - retval = kfifo_out(&device->tx_fifo, &size, sizeof(size_t)); 596 - if (retval != sizeof(size_t)) { 597 - dev_dbg(device->dev, 598 - "reading msg size from fifo failed: got %d, expected %d\n", 599 - retval, (unsigned int)sizeof(size_t)); 600 - continue; 601 - } 602 - 603 - /* use fixed message length, if requested */ 604 - if (tx_cfg.fixed_message_length != 0) 605 - size = tx_cfg.fixed_message_length; 606 - 607 - /* increase size, if len byte is requested */ 608 - if (tx_cfg.enable_length_byte == OPTION_ON) 609 - size++; 610 - 611 - /* increase size, if adr byte is requested */ 612 - if (tx_cfg.enable_address_byte == OPTION_ON) 613 - size++; 614 - 615 - /* prime buffer */ 616 - memset(device->buffer, 0, size); 617 - position = 0; 618 - 619 - /* add length byte, if requested */ 620 - if (tx_cfg.enable_length_byte == OPTION_ON) 621 - /* 622 - * according to spec, length byte itself must be 623 - * excluded from the length calculation 624 - */ 625 - device->buffer[position++] = size - 1; 626 - 627 - /* add adr byte, if requested */ 628 - if (tx_cfg.enable_address_byte == OPTION_ON) 629 - device->buffer[position++] = tx_cfg.address_byte; 630 - 631 - /* finally get message data from fifo */ 632 - retval = kfifo_out(&device->tx_fifo, &device->buffer[position], 633 - sizeof(device->buffer) - position); 634 - dev_dbg(device->dev, 635 - "read %d message byte(s) from fifo queue.\n", retval); 636 - 637 - /* 638 - * if rx is active, we need to interrupt the waiting for 639 - * incoming telegrams, to be able to send something. 640 - * We are only allowed, if currently no reception takes 641 - * place otherwise we need to wait for the incoming telegram 642 - * to finish 643 - */ 644 - wait_event_interruptible(device->tx_wait_queue, 645 - !device->rx_active || 646 - device->interrupt_rx_allowed); 647 - 648 - /* 649 - * prevent race conditions 650 - * irq will be reenabled after tx config is set 651 - */ 652 - disable_irq(device->irq_num[DIO0]); 653 - device->tx_active = true; 654 - 655 - /* clear fifo, set fifo threshold, set payload length */ 656 - retval = rf69_set_mode(spi, standby); /* this clears the fifo */ 657 - if (retval < 0) 658 - goto abort; 659 - 660 - if (device->rx_active && !rx_interrupted) { 661 - /* 662 - * rx is currently waiting for a telegram; 663 - * we need to set the radio module to standby 664 - */ 665 - rx_interrupted = true; 666 - } 667 - 668 - retval = rf69_set_fifo_threshold(spi, FIFO_THRESHOLD); 669 - if (retval < 0) 670 - goto abort; 671 - if (tx_cfg.enable_length_byte == OPTION_ON) { 672 - retval = rf69_set_payload_length(spi, size * tx_cfg.repetitions); 673 - if (retval < 0) 674 - goto abort; 675 - } else { 676 - retval = rf69_set_payload_length(spi, 0); 677 - if (retval < 0) 678 - goto abort; 679 - } 680 - 681 - /* configure the rf chip */ 682 - retval = rf69_set_tx_cfg(device, &tx_cfg); 683 - if (retval < 0) 684 - goto abort; 685 - 686 - /* enable fifo level interrupt */ 687 - retval = rf69_set_dio_mapping(spi, DIO1, DIO_FIFO_LEVEL); 688 - if (retval < 0) 689 - goto abort; 690 - device->irq_state[DIO1] = DIO_FIFO_LEVEL; 691 - irq_set_irq_type(device->irq_num[DIO1], IRQ_TYPE_EDGE_FALLING); 692 - 693 - /* enable packet sent interrupt */ 694 - retval = rf69_set_dio_mapping(spi, DIO0, DIO_PACKET_SENT); 695 - if (retval < 0) 696 - goto abort; 697 - device->irq_state[DIO0] = DIO_PACKET_SENT; 698 - irq_set_irq_type(device->irq_num[DIO0], IRQ_TYPE_EDGE_RISING); 699 - enable_irq(device->irq_num[DIO0]); /* was disabled by rx active check */ 700 - 701 - /* enable transmission */ 702 - retval = rf69_set_mode(spi, transmit); 703 - if (retval < 0) 704 - goto abort; 705 - 706 - /* transfer this msg (and repetitions) to chip fifo */ 707 - device->free_in_fifo = FIFO_SIZE; 708 - position = 0; 709 - repetitions = tx_cfg.repetitions; 710 - while ((repetitions > 0) && (size > position)) { 711 - if ((size - position) > device->free_in_fifo) { 712 - /* msg to big for fifo - take a part */ 713 - int write_size = device->free_in_fifo; 714 - 715 - device->free_in_fifo = 0; 716 - rf69_write_fifo(spi, 717 - &device->buffer[position], 718 - write_size); 719 - position += write_size; 720 - } else { 721 - /* msg fits into fifo - take all */ 722 - device->free_in_fifo -= size; 723 - repetitions--; 724 - rf69_write_fifo(spi, 725 - &device->buffer[position], 726 - (size - position)); 727 - position = 0; /* reset for next repetition */ 728 - } 729 - 730 - retval = wait_event_interruptible(device->fifo_wait_queue, 731 - device->free_in_fifo > 0); 732 - if (retval) { 733 - dev_dbg(device->dev, "ABORT\n"); 734 - goto abort; 735 - } 736 - } 737 - 738 - /* we are done. Wait for packet to get sent */ 739 - dev_dbg(device->dev, 740 - "thread: wait for packet to get sent/fifo to be empty\n"); 741 - wait_event_interruptible(device->fifo_wait_queue, 742 - device->free_in_fifo == FIFO_SIZE || 743 - kthread_should_stop()); 744 - if (kthread_should_stop()) 745 - return 0; 746 - 747 - /* STOP_TRANSMISSION */ 748 - dev_dbg(device->dev, "thread: Packet sent. Set mode to stby.\n"); 749 - retval = rf69_set_mode(spi, standby); 750 - if (retval < 0) 751 - goto abort; 752 - 753 - /* everything sent? */ 754 - if (kfifo_is_empty(&device->tx_fifo)) { 755 - abort: 756 - if (rx_interrupted) { 757 - rx_interrupted = false; 758 - pi433_start_rx(device); 759 - } 760 - device->tx_active = false; 761 - wake_up_interruptible(&device->rx_wait_queue); 762 - } 763 - } 764 - } 765 - 766 - /*-------------------------------------------------------------------------*/ 767 - 768 - static ssize_t 769 - pi433_read(struct file *filp, char __user *buf, size_t size, loff_t *f_pos) 770 - { 771 - struct pi433_instance *instance; 772 - struct pi433_device *device; 773 - int bytes_received; 774 - ssize_t retval; 775 - 776 - /* check, whether internal buffer is big enough for requested size */ 777 - if (size > MAX_MSG_SIZE) 778 - return -EMSGSIZE; 779 - 780 - instance = filp->private_data; 781 - device = instance->device; 782 - 783 - /* just one read request at a time */ 784 - mutex_lock(&device->rx_lock); 785 - if (device->rx_active) { 786 - mutex_unlock(&device->rx_lock); 787 - return -EAGAIN; 788 - } 789 - 790 - device->rx_active = true; 791 - mutex_unlock(&device->rx_lock); 792 - 793 - /* start receiving */ 794 - /* will block until something was received*/ 795 - device->rx_buffer_size = size; 796 - bytes_received = pi433_receive(device); 797 - 798 - /* release rx */ 799 - mutex_lock(&device->rx_lock); 800 - device->rx_active = false; 801 - mutex_unlock(&device->rx_lock); 802 - 803 - /* if read was successful copy to user space*/ 804 - if (bytes_received > 0) { 805 - retval = copy_to_user(buf, device->rx_buffer, bytes_received); 806 - if (retval) 807 - return -EFAULT; 808 - } 809 - 810 - return bytes_received; 811 - } 812 - 813 - static ssize_t 814 - pi433_write(struct file *filp, const char __user *buf, 815 - size_t count, loff_t *f_pos) 816 - { 817 - struct pi433_instance *instance; 818 - struct pi433_device *device; 819 - int retval; 820 - unsigned int required, available, copied; 821 - 822 - instance = filp->private_data; 823 - device = instance->device; 824 - 825 - /* 826 - * check, whether internal buffer (tx thread) is big enough 827 - * for requested size 828 - */ 829 - if (count > MAX_MSG_SIZE) 830 - return -EMSGSIZE; 831 - 832 - /* 833 - * check if tx_cfg has been initialized otherwise we won't be able to 834 - * config the RF trasmitter correctly due to invalid settings 835 - */ 836 - if (!instance->tx_cfg_initialized) { 837 - dev_notice_once(device->dev, 838 - "write: failed due to unconfigured tx_cfg (see PI433_IOC_WR_TX_CFG)\n"); 839 - return -EINVAL; 840 - } 841 - 842 - /* 843 - * write the following sequence into fifo: 844 - * - tx_cfg 845 - * - size of message 846 - * - message 847 - */ 848 - mutex_lock(&device->tx_fifo_lock); 849 - 850 - required = sizeof(instance->tx_cfg) + sizeof(size_t) + count; 851 - available = kfifo_avail(&device->tx_fifo); 852 - if (required > available) { 853 - dev_dbg(device->dev, "write to fifo failed: %d bytes required but %d available\n", 854 - required, available); 855 - mutex_unlock(&device->tx_fifo_lock); 856 - return -EAGAIN; 857 - } 858 - 859 - retval = kfifo_in(&device->tx_fifo, &instance->tx_cfg, 860 - sizeof(instance->tx_cfg)); 861 - if (retval != sizeof(instance->tx_cfg)) 862 - goto abort; 863 - 864 - retval = kfifo_in(&device->tx_fifo, &count, sizeof(size_t)); 865 - if (retval != sizeof(size_t)) 866 - goto abort; 867 - 868 - retval = kfifo_from_user(&device->tx_fifo, buf, count, &copied); 869 - if (retval || copied != count) 870 - goto abort; 871 - 872 - mutex_unlock(&device->tx_fifo_lock); 873 - 874 - /* start transfer */ 875 - wake_up_interruptible(&device->tx_wait_queue); 876 - dev_dbg(device->dev, "write: generated new msg with %d bytes.\n", copied); 877 - 878 - return copied; 879 - 880 - abort: 881 - dev_warn(device->dev, 882 - "write to fifo failed, non recoverable: 0x%x\n", retval); 883 - mutex_unlock(&device->tx_fifo_lock); 884 - return -EAGAIN; 885 - } 886 - 887 - static long pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 888 - { 889 - struct pi433_instance *instance; 890 - struct pi433_device *device; 891 - struct pi433_tx_cfg tx_cfg; 892 - void __user *argp = (void __user *)arg; 893 - 894 - /* Check type and command number */ 895 - if (_IOC_TYPE(cmd) != PI433_IOC_MAGIC) 896 - return -ENOTTY; 897 - 898 - instance = filp->private_data; 899 - device = instance->device; 900 - 901 - if (!device) 902 - return -ESHUTDOWN; 903 - 904 - switch (cmd) { 905 - case PI433_IOC_RD_TX_CFG: 906 - if (copy_to_user(argp, &instance->tx_cfg, 907 - sizeof(struct pi433_tx_cfg))) 908 - return -EFAULT; 909 - break; 910 - case PI433_IOC_WR_TX_CFG: 911 - if (copy_from_user(&tx_cfg, argp, sizeof(struct pi433_tx_cfg))) 912 - return -EFAULT; 913 - mutex_lock(&device->tx_fifo_lock); 914 - memcpy(&instance->tx_cfg, &tx_cfg, sizeof(struct pi433_tx_cfg)); 915 - instance->tx_cfg_initialized = true; 916 - mutex_unlock(&device->tx_fifo_lock); 917 - break; 918 - case PI433_IOC_RD_RX_CFG: 919 - if (copy_to_user(argp, &device->rx_cfg, 920 - sizeof(struct pi433_rx_cfg))) 921 - return -EFAULT; 922 - break; 923 - case PI433_IOC_WR_RX_CFG: 924 - mutex_lock(&device->rx_lock); 925 - 926 - /* during pendig read request, change of config not allowed */ 927 - if (device->rx_active) { 928 - mutex_unlock(&device->rx_lock); 929 - return -EAGAIN; 930 - } 931 - 932 - if (copy_from_user(&device->rx_cfg, argp, 933 - sizeof(struct pi433_rx_cfg))) { 934 - mutex_unlock(&device->rx_lock); 935 - return -EFAULT; 936 - } 937 - 938 - mutex_unlock(&device->rx_lock); 939 - break; 940 - default: 941 - return -EINVAL; 942 - } 943 - 944 - return 0; 945 - } 946 - 947 - /*-------------------------------------------------------------------------*/ 948 - 949 - static int pi433_open(struct inode *inode, struct file *filp) 950 - { 951 - struct pi433_device *device; 952 - struct pi433_instance *instance; 953 - 954 - mutex_lock(&minor_lock); 955 - device = idr_find(&pi433_idr, iminor(inode)); 956 - mutex_unlock(&minor_lock); 957 - if (!device) { 958 - pr_debug("device: minor %d unknown.\n", iminor(inode)); 959 - return -ENODEV; 960 - } 961 - 962 - instance = kzalloc(sizeof(*instance), GFP_KERNEL); 963 - if (!instance) 964 - return -ENOMEM; 965 - 966 - /* setup instance data*/ 967 - instance->device = device; 968 - 969 - /* instance data as context */ 970 - filp->private_data = instance; 971 - stream_open(inode, filp); 972 - 973 - return 0; 974 - } 975 - 976 - static int pi433_release(struct inode *inode, struct file *filp) 977 - { 978 - struct pi433_instance *instance; 979 - 980 - instance = filp->private_data; 981 - kfree(instance); 982 - filp->private_data = NULL; 983 - 984 - return 0; 985 - } 986 - 987 - /*-------------------------------------------------------------------------*/ 988 - 989 - static int setup_gpio(struct pi433_device *device) 990 - { 991 - char name[5]; 992 - int retval; 993 - int i; 994 - const irq_handler_t DIO_irq_handler[NUM_DIO] = { 995 - DIO0_irq_handler, 996 - DIO1_irq_handler 997 - }; 998 - 999 - for (i = 0; i < NUM_DIO; i++) { 1000 - /* "construct" name and get the gpio descriptor */ 1001 - snprintf(name, sizeof(name), "DIO%d", i); 1002 - device->gpiod[i] = gpiod_get(&device->spi->dev, name, 1003 - 0 /*GPIOD_IN*/); 1004 - 1005 - if (device->gpiod[i] == ERR_PTR(-ENOENT)) { 1006 - dev_dbg(&device->spi->dev, 1007 - "Could not find entry for %s. Ignoring.\n", name); 1008 - continue; 1009 - } 1010 - 1011 - if (device->gpiod[i] == ERR_PTR(-EBUSY)) 1012 - dev_dbg(&device->spi->dev, "%s is busy.\n", name); 1013 - 1014 - if (IS_ERR(device->gpiod[i])) { 1015 - retval = PTR_ERR(device->gpiod[i]); 1016 - /* release already allocated gpios */ 1017 - for (i--; i >= 0; i--) { 1018 - free_irq(device->irq_num[i], device); 1019 - gpiod_put(device->gpiod[i]); 1020 - } 1021 - return retval; 1022 - } 1023 - 1024 - /* configure the pin */ 1025 - retval = gpiod_direction_input(device->gpiod[i]); 1026 - if (retval) 1027 - return retval; 1028 - 1029 - /* configure irq */ 1030 - device->irq_num[i] = gpiod_to_irq(device->gpiod[i]); 1031 - if (device->irq_num[i] < 0) { 1032 - device->gpiod[i] = ERR_PTR(-EINVAL); 1033 - return device->irq_num[i]; 1034 - } 1035 - retval = request_irq(device->irq_num[i], 1036 - DIO_irq_handler[i], 1037 - 0, /* flags */ 1038 - name, 1039 - device); 1040 - 1041 - if (retval) 1042 - return retval; 1043 - 1044 - dev_dbg(&device->spi->dev, "%s successfully configured\n", name); 1045 - } 1046 - 1047 - return 0; 1048 - } 1049 - 1050 - static void free_gpio(struct pi433_device *device) 1051 - { 1052 - int i; 1053 - 1054 - for (i = 0; i < NUM_DIO; i++) { 1055 - /* check if gpiod is valid */ 1056 - if (IS_ERR(device->gpiod[i])) 1057 - continue; 1058 - 1059 - free_irq(device->irq_num[i], device); 1060 - gpiod_put(device->gpiod[i]); 1061 - } 1062 - } 1063 - 1064 - static int pi433_get_minor(struct pi433_device *device) 1065 - { 1066 - int retval = -ENOMEM; 1067 - 1068 - mutex_lock(&minor_lock); 1069 - retval = idr_alloc(&pi433_idr, device, 0, N_PI433_MINORS, GFP_KERNEL); 1070 - if (retval >= 0) { 1071 - device->minor = retval; 1072 - retval = 0; 1073 - } else if (retval == -ENOSPC) { 1074 - dev_err(&device->spi->dev, "too many pi433 devices\n"); 1075 - retval = -EINVAL; 1076 - } 1077 - mutex_unlock(&minor_lock); 1078 - return retval; 1079 - } 1080 - 1081 - static void pi433_free_minor(struct pi433_device *dev) 1082 - { 1083 - mutex_lock(&minor_lock); 1084 - idr_remove(&pi433_idr, dev->minor); 1085 - mutex_unlock(&minor_lock); 1086 - } 1087 - 1088 - /*-------------------------------------------------------------------------*/ 1089 - 1090 - static const struct file_operations pi433_fops = { 1091 - .owner = THIS_MODULE, 1092 - /* 1093 - * REVISIT switch to aio primitives, so that userspace 1094 - * gets more complete API coverage. It'll simplify things 1095 - * too, except for the locking. 1096 - */ 1097 - .write = pi433_write, 1098 - .read = pi433_read, 1099 - .unlocked_ioctl = pi433_ioctl, 1100 - .compat_ioctl = compat_ptr_ioctl, 1101 - .open = pi433_open, 1102 - .release = pi433_release, 1103 - .llseek = no_llseek, 1104 - }; 1105 - 1106 - static int pi433_debugfs_regs_show(struct seq_file *m, void *p) 1107 - { 1108 - struct pi433_device *dev; 1109 - u8 reg_data[114]; 1110 - int i; 1111 - char *fmt = "0x%02x, 0x%02x\n"; 1112 - int ret; 1113 - 1114 - dev = m->private; 1115 - 1116 - mutex_lock(&dev->tx_fifo_lock); 1117 - mutex_lock(&dev->rx_lock); 1118 - 1119 - // wait for on-going operations to finish 1120 - ret = wait_event_interruptible(dev->rx_wait_queue, !dev->tx_active); 1121 - if (ret) 1122 - goto out_unlock; 1123 - 1124 - ret = wait_event_interruptible(dev->tx_wait_queue, !dev->rx_active); 1125 - if (ret) 1126 - goto out_unlock; 1127 - 1128 - // skip FIFO register (0x0) otherwise this can affect some of uC ops 1129 - for (i = 1; i < 0x50; i++) 1130 - reg_data[i] = rf69_read_reg(dev->spi, i); 1131 - 1132 - reg_data[REG_TESTLNA] = rf69_read_reg(dev->spi, REG_TESTLNA); 1133 - reg_data[REG_TESTPA1] = rf69_read_reg(dev->spi, REG_TESTPA1); 1134 - reg_data[REG_TESTPA2] = rf69_read_reg(dev->spi, REG_TESTPA2); 1135 - reg_data[REG_TESTDAGC] = rf69_read_reg(dev->spi, REG_TESTDAGC); 1136 - reg_data[REG_TESTAFC] = rf69_read_reg(dev->spi, REG_TESTAFC); 1137 - 1138 - seq_puts(m, "# reg, val\n"); 1139 - 1140 - for (i = 1; i < 0x50; i++) 1141 - seq_printf(m, fmt, i, reg_data[i]); 1142 - 1143 - seq_printf(m, fmt, REG_TESTLNA, reg_data[REG_TESTLNA]); 1144 - seq_printf(m, fmt, REG_TESTPA1, reg_data[REG_TESTPA1]); 1145 - seq_printf(m, fmt, REG_TESTPA2, reg_data[REG_TESTPA2]); 1146 - seq_printf(m, fmt, REG_TESTDAGC, reg_data[REG_TESTDAGC]); 1147 - seq_printf(m, fmt, REG_TESTAFC, reg_data[REG_TESTAFC]); 1148 - 1149 - out_unlock: 1150 - mutex_unlock(&dev->rx_lock); 1151 - mutex_unlock(&dev->tx_fifo_lock); 1152 - 1153 - return ret; 1154 - } 1155 - DEFINE_SHOW_ATTRIBUTE(pi433_debugfs_regs); 1156 - 1157 - /*-------------------------------------------------------------------------*/ 1158 - 1159 - static int pi433_probe(struct spi_device *spi) 1160 - { 1161 - struct pi433_device *device; 1162 - int retval; 1163 - struct dentry *entry; 1164 - 1165 - /* setup spi parameters */ 1166 - spi->mode = 0x00; 1167 - spi->bits_per_word = 8; 1168 - /* 1169 - * spi->max_speed_hz = 10000000; 1170 - * 1MHz already set by device tree overlay 1171 - */ 1172 - 1173 - retval = spi_setup(spi); 1174 - if (retval) { 1175 - dev_dbg(&spi->dev, "configuration of SPI interface failed!\n"); 1176 - return retval; 1177 - } 1178 - 1179 - dev_dbg(&spi->dev, 1180 - "spi interface setup: mode 0x%2x, %d bits per word, %dhz max speed\n", 1181 - spi->mode, spi->bits_per_word, spi->max_speed_hz); 1182 - 1183 - /* read chip version */ 1184 - retval = rf69_get_version(spi); 1185 - if (retval < 0) 1186 - return retval; 1187 - 1188 - switch (retval) { 1189 - case 0x24: 1190 - dev_dbg(&spi->dev, "found pi433 (ver. 0x%x)\n", retval); 1191 - break; 1192 - default: 1193 - dev_dbg(&spi->dev, "unknown chip version: 0x%x\n", retval); 1194 - return -ENODEV; 1195 - } 1196 - 1197 - /* Allocate driver data */ 1198 - device = kzalloc(sizeof(*device), GFP_KERNEL); 1199 - if (!device) 1200 - return -ENOMEM; 1201 - 1202 - /* Initialize the driver data */ 1203 - device->spi = spi; 1204 - device->rx_active = false; 1205 - device->tx_active = false; 1206 - device->interrupt_rx_allowed = false; 1207 - 1208 - /* init rx buffer */ 1209 - device->rx_buffer = kmalloc(MAX_MSG_SIZE, GFP_KERNEL); 1210 - if (!device->rx_buffer) { 1211 - retval = -ENOMEM; 1212 - goto RX_failed; 1213 - } 1214 - 1215 - /* init wait queues */ 1216 - init_waitqueue_head(&device->tx_wait_queue); 1217 - init_waitqueue_head(&device->rx_wait_queue); 1218 - init_waitqueue_head(&device->fifo_wait_queue); 1219 - 1220 - /* init fifo */ 1221 - INIT_KFIFO(device->tx_fifo); 1222 - 1223 - /* init mutexes and locks */ 1224 - mutex_init(&device->tx_fifo_lock); 1225 - mutex_init(&device->rx_lock); 1226 - 1227 - /* setup GPIO (including irq_handler) for the different DIOs */ 1228 - retval = setup_gpio(device); 1229 - if (retval) { 1230 - dev_dbg(&spi->dev, "setup of GPIOs failed\n"); 1231 - goto GPIO_failed; 1232 - } 1233 - 1234 - /* setup the radio module */ 1235 - retval = rf69_set_mode(spi, standby); 1236 - if (retval < 0) 1237 - goto minor_failed; 1238 - retval = rf69_set_data_mode(spi, DATAMODUL_MODE_PACKET); 1239 - if (retval < 0) 1240 - goto minor_failed; 1241 - retval = rf69_enable_amplifier(spi, MASK_PALEVEL_PA0); 1242 - if (retval < 0) 1243 - goto minor_failed; 1244 - retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA1); 1245 - if (retval < 0) 1246 - goto minor_failed; 1247 - retval = rf69_disable_amplifier(spi, MASK_PALEVEL_PA2); 1248 - if (retval < 0) 1249 - goto minor_failed; 1250 - retval = rf69_set_output_power_level(spi, 13); 1251 - if (retval < 0) 1252 - goto minor_failed; 1253 - retval = rf69_set_antenna_impedance(spi, fifty_ohm); 1254 - if (retval < 0) 1255 - goto minor_failed; 1256 - 1257 - /* determ minor number */ 1258 - retval = pi433_get_minor(device); 1259 - if (retval) { 1260 - dev_dbg(&spi->dev, "get of minor number failed\n"); 1261 - goto minor_failed; 1262 - } 1263 - 1264 - /* create device */ 1265 - device->devt = MKDEV(MAJOR(pi433_dev), device->minor); 1266 - device->dev = device_create(&pi433_class, 1267 - &spi->dev, 1268 - device->devt, 1269 - device, 1270 - "pi433.%d", 1271 - device->minor); 1272 - if (IS_ERR(device->dev)) { 1273 - pr_err("pi433: device register failed\n"); 1274 - retval = PTR_ERR(device->dev); 1275 - goto device_create_failed; 1276 - } else { 1277 - dev_dbg(device->dev, 1278 - "created device for major %d, minor %d\n", 1279 - MAJOR(pi433_dev), 1280 - device->minor); 1281 - } 1282 - 1283 - /* start tx thread */ 1284 - device->tx_task_struct = kthread_run(pi433_tx_thread, 1285 - device, 1286 - "pi433.%d_tx_task", 1287 - device->minor); 1288 - if (IS_ERR(device->tx_task_struct)) { 1289 - dev_dbg(device->dev, "start of send thread failed\n"); 1290 - retval = PTR_ERR(device->tx_task_struct); 1291 - goto send_thread_failed; 1292 - } 1293 - 1294 - /* create cdev */ 1295 - device->cdev = cdev_alloc(); 1296 - if (!device->cdev) { 1297 - dev_dbg(device->dev, "allocation of cdev failed\n"); 1298 - retval = -ENOMEM; 1299 - goto cdev_failed; 1300 - } 1301 - device->cdev->owner = THIS_MODULE; 1302 - cdev_init(device->cdev, &pi433_fops); 1303 - retval = cdev_add(device->cdev, device->devt, 1); 1304 - if (retval) { 1305 - dev_dbg(device->dev, "register of cdev failed\n"); 1306 - goto del_cdev; 1307 - } 1308 - 1309 - /* spi setup */ 1310 - spi_set_drvdata(spi, device); 1311 - 1312 - entry = debugfs_create_dir(dev_name(device->dev), root_dir); 1313 - debugfs_create_file("regs", 0400, entry, device, &pi433_debugfs_regs_fops); 1314 - 1315 - return 0; 1316 - 1317 - del_cdev: 1318 - cdev_del(device->cdev); 1319 - cdev_failed: 1320 - kthread_stop(device->tx_task_struct); 1321 - send_thread_failed: 1322 - device_destroy(&pi433_class, device->devt); 1323 - device_create_failed: 1324 - pi433_free_minor(device); 1325 - minor_failed: 1326 - free_gpio(device); 1327 - GPIO_failed: 1328 - kfree(device->rx_buffer); 1329 - RX_failed: 1330 - kfree(device); 1331 - 1332 - return retval; 1333 - } 1334 - 1335 - static void pi433_remove(struct spi_device *spi) 1336 - { 1337 - struct pi433_device *device = spi_get_drvdata(spi); 1338 - 1339 - debugfs_lookup_and_remove(dev_name(device->dev), root_dir); 1340 - 1341 - /* free GPIOs */ 1342 - free_gpio(device); 1343 - 1344 - /* make sure ops on existing fds can abort cleanly */ 1345 - device->spi = NULL; 1346 - 1347 - kthread_stop(device->tx_task_struct); 1348 - 1349 - device_destroy(&pi433_class, device->devt); 1350 - 1351 - cdev_del(device->cdev); 1352 - 1353 - pi433_free_minor(device); 1354 - 1355 - kfree(device->rx_buffer); 1356 - kfree(device); 1357 - } 1358 - 1359 - static const struct of_device_id pi433_dt_ids[] = { 1360 - { .compatible = "Smarthome-Wolf,pi433" }, 1361 - {}, 1362 - }; 1363 - 1364 - MODULE_DEVICE_TABLE(of, pi433_dt_ids); 1365 - 1366 - static struct spi_driver pi433_spi_driver = { 1367 - .driver = { 1368 - .name = "pi433", 1369 - .owner = THIS_MODULE, 1370 - .of_match_table = of_match_ptr(pi433_dt_ids), 1371 - }, 1372 - .probe = pi433_probe, 1373 - .remove = pi433_remove, 1374 - 1375 - /* 1376 - * NOTE: suspend/resume methods are not necessary here. 1377 - * We don't do anything except pass the requests to/from 1378 - * the underlying controller. The refrigerator handles 1379 - * most issues; the controller driver handles the rest. 1380 - */ 1381 - }; 1382 - 1383 - /*-------------------------------------------------------------------------*/ 1384 - 1385 - static int __init pi433_init(void) 1386 - { 1387 - int status; 1388 - 1389 - /* 1390 - * If MAX_MSG_SIZE is smaller then FIFO_SIZE, the driver won't 1391 - * work stable - risk of buffer overflow 1392 - */ 1393 - if (MAX_MSG_SIZE < FIFO_SIZE) 1394 - return -EINVAL; 1395 - 1396 - /* 1397 - * Claim device numbers. Then register a class 1398 - * that will key udev/mdev to add/remove /dev nodes. 1399 - * Last, register the driver which manages those device numbers. 1400 - */ 1401 - status = alloc_chrdev_region(&pi433_dev, 0, N_PI433_MINORS, "pi433"); 1402 - if (status < 0) 1403 - return status; 1404 - 1405 - status = class_register(&pi433_class); 1406 - if (status) { 1407 - unregister_chrdev(MAJOR(pi433_dev), 1408 - pi433_spi_driver.driver.name); 1409 - return status; 1410 - } 1411 - 1412 - root_dir = debugfs_create_dir(KBUILD_MODNAME, NULL); 1413 - 1414 - status = spi_register_driver(&pi433_spi_driver); 1415 - if (status < 0) { 1416 - class_unregister(&pi433_class); 1417 - unregister_chrdev(MAJOR(pi433_dev), 1418 - pi433_spi_driver.driver.name); 1419 - } 1420 - 1421 - return status; 1422 - } 1423 - 1424 - module_init(pi433_init); 1425 - 1426 - static void __exit pi433_exit(void) 1427 - { 1428 - spi_unregister_driver(&pi433_spi_driver); 1429 - class_unregister(&pi433_class); 1430 - unregister_chrdev(MAJOR(pi433_dev), pi433_spi_driver.driver.name); 1431 - debugfs_remove(root_dir); 1432 - } 1433 - module_exit(pi433_exit); 1434 - 1435 - MODULE_AUTHOR("Marcus Wolf, <linux@wolf-entwicklungen.de>"); 1436 - MODULE_DESCRIPTION("Driver for Pi433"); 1437 - MODULE_LICENSE("GPL"); 1438 - MODULE_ALIAS("spi:pi433");
-148
drivers/staging/pi433/pi433_if.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * userspace interface for pi433 radio module 4 - * 5 - * Pi433 is a 433MHz radio module for the Raspberry Pi. 6 - * It is based on the HopeRf Module RFM69CW. Therefore, inside of this 7 - * driver you'll find an abstraction of the rf69 chip. 8 - * 9 - * If needed this driver could also be extended to support other 10 - * devices based on HopeRf rf69 as well as HopeRf modules with a similar 11 - * interface such as RFM69HCW, RFM12, RFM95 and so on. 12 - * 13 - * Copyright (C) 2016 Wolf-Entwicklungen 14 - * Marcus Wolf <linux@wolf-entwicklungen.de> 15 - */ 16 - 17 - #ifndef PI433_H 18 - #define PI433_H 19 - 20 - #include <linux/types.h> 21 - #include "rf69_enum.h" 22 - 23 - /*---------------------------------------------------------------------------*/ 24 - 25 - enum option_on_off { 26 - OPTION_OFF, 27 - OPTION_ON 28 - }; 29 - 30 - /* IOCTL structs and commands */ 31 - 32 - /** 33 - * struct pi433_tx_cfg 34 - * describes the configuration of the radio module for sending data 35 - * @frequency: 36 - * @bit_rate: 37 - * @modulation: 38 - * @data_mode: 39 - * @preamble_length: 40 - * @sync_pattern: 41 - * @tx_start_condition: 42 - * @payload_length: 43 - * @repetitions: 44 - * 45 - * ATTENTION: 46 - * If the contents of 'pi433_tx_cfg' ever change 47 - * incompatibly, then the ioctl number (see define below) must change. 48 - * 49 - * NOTE: struct layout is the same in 64bit and 32bit userspace. 50 - */ 51 - #define PI433_TX_CFG_IOCTL_NR 0 52 - struct pi433_tx_cfg { 53 - __u32 frequency; 54 - __u16 bit_rate; 55 - __u32 dev_frequency; 56 - enum modulation modulation; 57 - enum mod_shaping mod_shaping; 58 - 59 - enum pa_ramp pa_ramp; 60 - 61 - enum tx_start_condition tx_start_condition; 62 - 63 - __u16 repetitions; 64 - 65 - /* packet format */ 66 - enum option_on_off enable_preamble; 67 - enum option_on_off enable_sync; 68 - enum option_on_off enable_length_byte; 69 - enum option_on_off enable_address_byte; 70 - enum option_on_off enable_crc; 71 - 72 - __u16 preamble_length; 73 - __u8 sync_length; 74 - __u8 fixed_message_length; 75 - 76 - __u8 sync_pattern[8]; 77 - __u8 address_byte; 78 - }; 79 - 80 - /** 81 - * struct pi433_rx_cfg 82 - * describes the configuration of the radio module for receiving data 83 - * @frequency: 84 - * @bit_rate: 85 - * @modulation: 86 - * @data_mode: 87 - * @preamble_length: 88 - * @sync_pattern: 89 - * @tx_start_condition: 90 - * @payload_length: 91 - * @repetitions: 92 - * 93 - * ATTENTION: 94 - * If the contents of 'pi433_rx_cfg' ever change 95 - * incompatibly, then the ioctl number (see define below) must change 96 - * 97 - * NOTE: struct layout is the same in 64bit and 32bit userspace. 98 - */ 99 - #define PI433_RX_CFG_IOCTL_NR 1 100 - struct pi433_rx_cfg { 101 - __u32 frequency; 102 - __u16 bit_rate; 103 - __u32 dev_frequency; 104 - 105 - enum modulation modulation; 106 - 107 - __u8 rssi_threshold; 108 - enum threshold_decrement threshold_decrement; 109 - enum antenna_impedance antenna_impedance; 110 - enum lna_gain lna_gain; 111 - enum mantisse bw_mantisse; /* normal: 0x50 */ 112 - __u8 bw_exponent; /* during AFC: 0x8b */ 113 - enum dagc dagc; 114 - 115 - /* packet format */ 116 - enum option_on_off enable_sync; 117 - 118 - /* should be used in combination with sync, only */ 119 - enum option_on_off enable_length_byte; 120 - 121 - /* operational with sync, only */ 122 - enum address_filtering enable_address_filtering; 123 - 124 - /* only operational, if sync on and fixed length or length byte is used */ 125 - enum option_on_off enable_crc; 126 - 127 - __u8 sync_length; 128 - __u8 fixed_message_length; 129 - __u32 bytes_to_drop; 130 - 131 - __u8 sync_pattern[8]; 132 - __u8 node_address; 133 - __u8 broadcast_address; 134 - }; 135 - 136 - #define PI433_IOC_MAGIC 'r' 137 - 138 - #define PI433_IOC_RD_TX_CFG \ 139 - _IOR(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)]) 140 - #define PI433_IOC_WR_TX_CFG \ 141 - _IOW(PI433_IOC_MAGIC, PI433_TX_CFG_IOCTL_NR, char[sizeof(struct pi433_tx_cfg)]) 142 - 143 - #define PI433_IOC_RD_RX_CFG \ 144 - _IOR(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)]) 145 - #define PI433_IOC_WR_RX_CFG \ 146 - _IOW(PI433_IOC_MAGIC, PI433_RX_CFG_IOCTL_NR, char[sizeof(struct pi433_rx_cfg)]) 147 - 148 - #endif /* PI433_H */
-832
drivers/staging/pi433/rf69.c
··· 1 - // SPDX-License-Identifier: GPL-2.0+ 2 - /* 3 - * abstraction of the spi interface of HopeRf rf69 radio module 4 - * 5 - * Copyright (C) 2016 Wolf-Entwicklungen 6 - * Marcus Wolf <linux@wolf-entwicklungen.de> 7 - */ 8 - 9 - #include <linux/types.h> 10 - #include <linux/spi/spi.h> 11 - #include <linux/units.h> 12 - 13 - #include "rf69.h" 14 - #include "rf69_registers.h" 15 - 16 - #define F_OSC (32 * HZ_PER_MHZ) 17 - 18 - /*-------------------------------------------------------------------------*/ 19 - 20 - u8 rf69_read_reg(struct spi_device *spi, u8 addr) 21 - { 22 - return spi_w8r8(spi, addr); 23 - } 24 - 25 - static int rf69_write_reg(struct spi_device *spi, u8 addr, u8 value) 26 - { 27 - char buffer[2]; 28 - 29 - buffer[0] = addr | WRITE_BIT; 30 - buffer[1] = value; 31 - 32 - return spi_write(spi, &buffer, ARRAY_SIZE(buffer)); 33 - } 34 - 35 - /*-------------------------------------------------------------------------*/ 36 - 37 - static int rf69_set_bit(struct spi_device *spi, u8 reg, u8 mask) 38 - { 39 - u8 tmp; 40 - 41 - tmp = rf69_read_reg(spi, reg); 42 - tmp = tmp | mask; 43 - return rf69_write_reg(spi, reg, tmp); 44 - } 45 - 46 - static int rf69_clear_bit(struct spi_device *spi, u8 reg, u8 mask) 47 - { 48 - u8 tmp; 49 - 50 - tmp = rf69_read_reg(spi, reg); 51 - tmp = tmp & ~mask; 52 - return rf69_write_reg(spi, reg, tmp); 53 - } 54 - 55 - static inline int rf69_read_mod_write(struct spi_device *spi, u8 reg, 56 - u8 mask, u8 value) 57 - { 58 - u8 tmp; 59 - 60 - tmp = rf69_read_reg(spi, reg); 61 - tmp = (tmp & ~mask) | value; 62 - return rf69_write_reg(spi, reg, tmp); 63 - } 64 - 65 - /*-------------------------------------------------------------------------*/ 66 - 67 - int rf69_get_version(struct spi_device *spi) 68 - { 69 - return rf69_read_reg(spi, REG_VERSION); 70 - } 71 - 72 - int rf69_set_mode(struct spi_device *spi, enum mode mode) 73 - { 74 - static const u8 mode_map[] = { 75 - [transmit] = OPMODE_MODE_TRANSMIT, 76 - [receive] = OPMODE_MODE_RECEIVE, 77 - [synthesizer] = OPMODE_MODE_SYNTHESIZER, 78 - [standby] = OPMODE_MODE_STANDBY, 79 - [mode_sleep] = OPMODE_MODE_SLEEP, 80 - }; 81 - 82 - if (unlikely(mode >= ARRAY_SIZE(mode_map))) { 83 - dev_dbg(&spi->dev, "set: illegal mode %u\n", mode); 84 - return -EINVAL; 85 - } 86 - 87 - return rf69_read_mod_write(spi, REG_OPMODE, MASK_OPMODE_MODE, 88 - mode_map[mode]); 89 - 90 - /* 91 - * we are using packet mode, so this check is not really needed 92 - * but waiting for mode ready is necessary when going from sleep 93 - * because the FIFO may not be immediately available from previous mode 94 - * while (_mode == RF69_MODE_SLEEP && (READ_REG(REG_IRQFLAGS1) & 95 - RF_IRQFLAGS1_MODEREADY) == 0x00); // Wait for ModeReady 96 - */ 97 - } 98 - 99 - int rf69_set_data_mode(struct spi_device *spi, u8 data_mode) 100 - { 101 - return rf69_read_mod_write(spi, REG_DATAMODUL, MASK_DATAMODUL_MODE, 102 - data_mode); 103 - } 104 - 105 - int rf69_set_modulation(struct spi_device *spi, enum modulation modulation) 106 - { 107 - static const u8 modulation_map[] = { 108 - [OOK] = DATAMODUL_MODULATION_TYPE_OOK, 109 - [FSK] = DATAMODUL_MODULATION_TYPE_FSK, 110 - }; 111 - 112 - if (unlikely(modulation >= ARRAY_SIZE(modulation_map))) { 113 - dev_dbg(&spi->dev, "set: illegal modulation %u\n", modulation); 114 - return -EINVAL; 115 - } 116 - 117 - return rf69_read_mod_write(spi, REG_DATAMODUL, 118 - MASK_DATAMODUL_MODULATION_TYPE, 119 - modulation_map[modulation]); 120 - } 121 - 122 - static enum modulation rf69_get_modulation(struct spi_device *spi) 123 - { 124 - u8 modulation_reg; 125 - 126 - modulation_reg = rf69_read_reg(spi, REG_DATAMODUL); 127 - 128 - switch (modulation_reg & MASK_DATAMODUL_MODULATION_TYPE) { 129 - case DATAMODUL_MODULATION_TYPE_OOK: 130 - return OOK; 131 - case DATAMODUL_MODULATION_TYPE_FSK: 132 - return FSK; 133 - default: 134 - return UNDEF; 135 - } 136 - } 137 - 138 - int rf69_set_modulation_shaping(struct spi_device *spi, 139 - enum mod_shaping mod_shaping) 140 - { 141 - switch (rf69_get_modulation(spi)) { 142 - case FSK: 143 - switch (mod_shaping) { 144 - case SHAPING_OFF: 145 - return rf69_read_mod_write(spi, REG_DATAMODUL, 146 - MASK_DATAMODUL_MODULATION_SHAPE, 147 - DATAMODUL_MODULATION_SHAPE_NONE); 148 - case SHAPING_1_0: 149 - return rf69_read_mod_write(spi, REG_DATAMODUL, 150 - MASK_DATAMODUL_MODULATION_SHAPE, 151 - DATAMODUL_MODULATION_SHAPE_1_0); 152 - case SHAPING_0_5: 153 - return rf69_read_mod_write(spi, REG_DATAMODUL, 154 - MASK_DATAMODUL_MODULATION_SHAPE, 155 - DATAMODUL_MODULATION_SHAPE_0_5); 156 - case SHAPING_0_3: 157 - return rf69_read_mod_write(spi, REG_DATAMODUL, 158 - MASK_DATAMODUL_MODULATION_SHAPE, 159 - DATAMODUL_MODULATION_SHAPE_0_3); 160 - default: 161 - dev_dbg(&spi->dev, "set: illegal mod shaping for FSK %u\n", mod_shaping); 162 - return -EINVAL; 163 - } 164 - case OOK: 165 - switch (mod_shaping) { 166 - case SHAPING_OFF: 167 - return rf69_read_mod_write(spi, REG_DATAMODUL, 168 - MASK_DATAMODUL_MODULATION_SHAPE, 169 - DATAMODUL_MODULATION_SHAPE_NONE); 170 - case SHAPING_BR: 171 - return rf69_read_mod_write(spi, REG_DATAMODUL, 172 - MASK_DATAMODUL_MODULATION_SHAPE, 173 - DATAMODUL_MODULATION_SHAPE_BR); 174 - case SHAPING_2BR: 175 - return rf69_read_mod_write(spi, REG_DATAMODUL, 176 - MASK_DATAMODUL_MODULATION_SHAPE, 177 - DATAMODUL_MODULATION_SHAPE_2BR); 178 - default: 179 - dev_dbg(&spi->dev, "set: illegal mod shaping for OOK %u\n", mod_shaping); 180 - return -EINVAL; 181 - } 182 - default: 183 - dev_dbg(&spi->dev, "set: modulation undefined\n"); 184 - return -EINVAL; 185 - } 186 - } 187 - 188 - int rf69_set_bit_rate(struct spi_device *spi, u16 bit_rate) 189 - { 190 - int retval; 191 - u32 bit_rate_reg; 192 - u8 msb; 193 - u8 lsb; 194 - enum modulation mod; 195 - 196 - // check if modulation is configured 197 - mod = rf69_get_modulation(spi); 198 - if (mod == UNDEF) { 199 - dev_dbg(&spi->dev, "setBitRate: modulation is undefined\n"); 200 - return -EINVAL; 201 - } 202 - 203 - // check input value 204 - if (bit_rate < 1200 || (mod == OOK && bit_rate > 32768)) { 205 - dev_dbg(&spi->dev, "setBitRate: illegal input param\n"); 206 - return -EINVAL; 207 - } 208 - 209 - // calculate reg settings 210 - bit_rate_reg = (F_OSC / bit_rate); 211 - 212 - msb = (bit_rate_reg & 0xff00) >> 8; 213 - lsb = (bit_rate_reg & 0xff); 214 - 215 - // transmit to RF 69 216 - retval = rf69_write_reg(spi, REG_BITRATE_MSB, msb); 217 - if (retval) 218 - return retval; 219 - retval = rf69_write_reg(spi, REG_BITRATE_LSB, lsb); 220 - if (retval) 221 - return retval; 222 - 223 - return 0; 224 - } 225 - 226 - int rf69_set_deviation(struct spi_device *spi, u32 deviation) 227 - { 228 - int retval; 229 - u64 f_reg; 230 - u64 f_step; 231 - u32 bit_rate_reg; 232 - u32 bit_rate; 233 - u8 msb; 234 - u8 lsb; 235 - u64 factor = 1000000; // to improve precision of calculation 236 - 237 - // calculate bit rate 238 - bit_rate_reg = rf69_read_reg(spi, REG_BITRATE_MSB) << 8; 239 - bit_rate_reg |= rf69_read_reg(spi, REG_BITRATE_LSB); 240 - bit_rate = F_OSC / bit_rate_reg; 241 - 242 - /* 243 - * frequency deviation must exceed 600 Hz but not exceed 244 - * 500kHz when taking bitrate dependency into consideration 245 - * to ensure proper modulation 246 - */ 247 - if (deviation < 600 || (deviation + (bit_rate / 2)) > 500000) { 248 - dev_dbg(&spi->dev, 249 - "set_deviation: illegal input param: %u\n", deviation); 250 - return -EINVAL; 251 - } 252 - 253 - // calculat f step 254 - f_step = F_OSC * factor; 255 - do_div(f_step, 524288); // 524288 = 2^19 256 - 257 - // calculate register settings 258 - f_reg = deviation * factor; 259 - do_div(f_reg, f_step); 260 - 261 - msb = (f_reg & 0xff00) >> 8; 262 - lsb = (f_reg & 0xff); 263 - 264 - // check msb 265 - if (msb & ~FDEVMASB_MASK) { 266 - dev_dbg(&spi->dev, "set_deviation: err in calc of msb\n"); 267 - return -EINVAL; 268 - } 269 - 270 - // write to chip 271 - retval = rf69_write_reg(spi, REG_FDEV_MSB, msb); 272 - if (retval) 273 - return retval; 274 - retval = rf69_write_reg(spi, REG_FDEV_LSB, lsb); 275 - if (retval) 276 - return retval; 277 - 278 - return 0; 279 - } 280 - 281 - int rf69_set_frequency(struct spi_device *spi, u32 frequency) 282 - { 283 - int retval; 284 - u32 f_max; 285 - u64 f_reg; 286 - u64 f_step; 287 - u8 msb; 288 - u8 mid; 289 - u8 lsb; 290 - u64 factor = 1000000; // to improve precision of calculation 291 - 292 - // calculat f step 293 - f_step = F_OSC * factor; 294 - do_div(f_step, 524288); // 524288 = 2^19 295 - 296 - // check input value 297 - f_max = div_u64(f_step * 8388608, factor); 298 - if (frequency > f_max) { 299 - dev_dbg(&spi->dev, "setFrequency: illegal input param\n"); 300 - return -EINVAL; 301 - } 302 - 303 - // calculate reg settings 304 - f_reg = frequency * factor; 305 - do_div(f_reg, f_step); 306 - 307 - msb = (f_reg & 0xff0000) >> 16; 308 - mid = (f_reg & 0xff00) >> 8; 309 - lsb = (f_reg & 0xff); 310 - 311 - // write to chip 312 - retval = rf69_write_reg(spi, REG_FRF_MSB, msb); 313 - if (retval) 314 - return retval; 315 - retval = rf69_write_reg(spi, REG_FRF_MID, mid); 316 - if (retval) 317 - return retval; 318 - retval = rf69_write_reg(spi, REG_FRF_LSB, lsb); 319 - if (retval) 320 - return retval; 321 - 322 - return 0; 323 - } 324 - 325 - int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask) 326 - { 327 - return rf69_set_bit(spi, REG_PALEVEL, amplifier_mask); 328 - } 329 - 330 - int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask) 331 - { 332 - return rf69_clear_bit(spi, REG_PALEVEL, amplifier_mask); 333 - } 334 - 335 - int rf69_set_output_power_level(struct spi_device *spi, u8 power_level) 336 - { 337 - u8 pa_level, ocp, test_pa1, test_pa2; 338 - bool pa0, pa1, pa2, high_power; 339 - u8 min_power_level; 340 - 341 - // check register pa_level 342 - pa_level = rf69_read_reg(spi, REG_PALEVEL); 343 - pa0 = pa_level & MASK_PALEVEL_PA0; 344 - pa1 = pa_level & MASK_PALEVEL_PA1; 345 - pa2 = pa_level & MASK_PALEVEL_PA2; 346 - 347 - // check high power mode 348 - ocp = rf69_read_reg(spi, REG_OCP); 349 - test_pa1 = rf69_read_reg(spi, REG_TESTPA1); 350 - test_pa2 = rf69_read_reg(spi, REG_TESTPA2); 351 - high_power = (ocp == 0x0f) && (test_pa1 == 0x5d) && (test_pa2 == 0x7c); 352 - 353 - if (pa0 && !pa1 && !pa2) { 354 - power_level += 18; 355 - min_power_level = 0; 356 - } else if (!pa0 && pa1 && !pa2) { 357 - power_level += 18; 358 - min_power_level = 16; 359 - } else if (!pa0 && pa1 && pa2) { 360 - if (high_power) 361 - power_level += 11; 362 - else 363 - power_level += 14; 364 - min_power_level = 16; 365 - } else { 366 - goto failed; 367 - } 368 - 369 - // check input value 370 - if (power_level > 0x1f) 371 - goto failed; 372 - 373 - if (power_level < min_power_level) 374 - goto failed; 375 - 376 - // write value 377 - return rf69_read_mod_write(spi, REG_PALEVEL, MASK_PALEVEL_OUTPUT_POWER, 378 - power_level); 379 - failed: 380 - dev_dbg(&spi->dev, "set: illegal power level %u\n", power_level); 381 - return -EINVAL; 382 - } 383 - 384 - int rf69_set_pa_ramp(struct spi_device *spi, enum pa_ramp pa_ramp) 385 - { 386 - static const u8 pa_ramp_map[] = { 387 - [ramp3400] = PARAMP_3400, 388 - [ramp2000] = PARAMP_2000, 389 - [ramp1000] = PARAMP_1000, 390 - [ramp500] = PARAMP_500, 391 - [ramp250] = PARAMP_250, 392 - [ramp125] = PARAMP_125, 393 - [ramp100] = PARAMP_100, 394 - [ramp62] = PARAMP_62, 395 - [ramp50] = PARAMP_50, 396 - [ramp40] = PARAMP_40, 397 - [ramp31] = PARAMP_31, 398 - [ramp25] = PARAMP_25, 399 - [ramp20] = PARAMP_20, 400 - [ramp15] = PARAMP_15, 401 - [ramp10] = PARAMP_10, 402 - }; 403 - 404 - if (unlikely(pa_ramp >= ARRAY_SIZE(pa_ramp_map))) { 405 - dev_dbg(&spi->dev, "set: illegal pa_ramp %u\n", pa_ramp); 406 - return -EINVAL; 407 - } 408 - 409 - return rf69_write_reg(spi, REG_PARAMP, pa_ramp_map[pa_ramp]); 410 - } 411 - 412 - int rf69_set_antenna_impedance(struct spi_device *spi, 413 - enum antenna_impedance antenna_impedance) 414 - { 415 - switch (antenna_impedance) { 416 - case fifty_ohm: 417 - return rf69_clear_bit(spi, REG_LNA, MASK_LNA_ZIN); 418 - case two_hundred_ohm: 419 - return rf69_set_bit(spi, REG_LNA, MASK_LNA_ZIN); 420 - default: 421 - dev_dbg(&spi->dev, "set: illegal antenna impedance %u\n", antenna_impedance); 422 - return -EINVAL; 423 - } 424 - } 425 - 426 - int rf69_set_lna_gain(struct spi_device *spi, enum lna_gain lna_gain) 427 - { 428 - static const u8 lna_gain_map[] = { 429 - [automatic] = LNA_GAIN_AUTO, 430 - [max] = LNA_GAIN_MAX, 431 - [max_minus_6] = LNA_GAIN_MAX_MINUS_6, 432 - [max_minus_12] = LNA_GAIN_MAX_MINUS_12, 433 - [max_minus_24] = LNA_GAIN_MAX_MINUS_24, 434 - [max_minus_36] = LNA_GAIN_MAX_MINUS_36, 435 - [max_minus_48] = LNA_GAIN_MAX_MINUS_48, 436 - }; 437 - 438 - if (unlikely(lna_gain >= ARRAY_SIZE(lna_gain_map))) { 439 - dev_dbg(&spi->dev, "set: illegal lna gain %u\n", lna_gain); 440 - return -EINVAL; 441 - } 442 - 443 - return rf69_read_mod_write(spi, REG_LNA, MASK_LNA_GAIN, 444 - lna_gain_map[lna_gain]); 445 - } 446 - 447 - static int rf69_set_bandwidth_intern(struct spi_device *spi, u8 reg, 448 - enum mantisse mantisse, u8 exponent) 449 - { 450 - u8 bandwidth; 451 - 452 - // check value for mantisse and exponent 453 - if (exponent > 7) { 454 - dev_dbg(&spi->dev, "set: illegal bandwidth exponent %u\n", exponent); 455 - return -EINVAL; 456 - } 457 - 458 - if (mantisse != mantisse16 && 459 - mantisse != mantisse20 && 460 - mantisse != mantisse24) { 461 - dev_dbg(&spi->dev, "set: illegal bandwidth mantisse %u\n", mantisse); 462 - return -EINVAL; 463 - } 464 - 465 - // read old value 466 - bandwidth = rf69_read_reg(spi, reg); 467 - 468 - // "delete" mantisse and exponent = just keep the DCC setting 469 - bandwidth = bandwidth & MASK_BW_DCC_FREQ; 470 - 471 - // add new mantisse 472 - switch (mantisse) { 473 - case mantisse16: 474 - bandwidth = bandwidth | BW_MANT_16; 475 - break; 476 - case mantisse20: 477 - bandwidth = bandwidth | BW_MANT_20; 478 - break; 479 - case mantisse24: 480 - bandwidth = bandwidth | BW_MANT_24; 481 - break; 482 - } 483 - 484 - // add new exponent 485 - bandwidth = bandwidth | exponent; 486 - 487 - // write back 488 - return rf69_write_reg(spi, reg, bandwidth); 489 - } 490 - 491 - int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, 492 - u8 exponent) 493 - { 494 - return rf69_set_bandwidth_intern(spi, REG_RXBW, mantisse, exponent); 495 - } 496 - 497 - int rf69_set_bandwidth_during_afc(struct spi_device *spi, 498 - enum mantisse mantisse, 499 - u8 exponent) 500 - { 501 - return rf69_set_bandwidth_intern(spi, REG_AFCBW, mantisse, exponent); 502 - } 503 - 504 - int rf69_set_ook_threshold_dec(struct spi_device *spi, 505 - enum threshold_decrement threshold_decrement) 506 - { 507 - static const u8 td_map[] = { 508 - [dec_every8th] = OOKPEAK_THRESHDEC_EVERY_8TH, 509 - [dec_every4th] = OOKPEAK_THRESHDEC_EVERY_4TH, 510 - [dec_every2nd] = OOKPEAK_THRESHDEC_EVERY_2ND, 511 - [dec_once] = OOKPEAK_THRESHDEC_ONCE, 512 - [dec_twice] = OOKPEAK_THRESHDEC_TWICE, 513 - [dec_4times] = OOKPEAK_THRESHDEC_4_TIMES, 514 - [dec_8times] = OOKPEAK_THRESHDEC_8_TIMES, 515 - [dec_16times] = OOKPEAK_THRESHDEC_16_TIMES, 516 - }; 517 - 518 - if (unlikely(threshold_decrement >= ARRAY_SIZE(td_map))) { 519 - dev_dbg(&spi->dev, "set: illegal OOK threshold decrement %u\n", 520 - threshold_decrement); 521 - return -EINVAL; 522 - } 523 - 524 - return rf69_read_mod_write(spi, REG_OOKPEAK, MASK_OOKPEAK_THRESDEC, 525 - td_map[threshold_decrement]); 526 - } 527 - 528 - int rf69_set_dio_mapping(struct spi_device *spi, u8 dio_number, u8 value) 529 - { 530 - u8 mask; 531 - u8 shift; 532 - u8 dio_addr; 533 - u8 dio_value; 534 - 535 - switch (dio_number) { 536 - case 0: 537 - mask = MASK_DIO0; 538 - shift = SHIFT_DIO0; 539 - dio_addr = REG_DIOMAPPING1; 540 - break; 541 - case 1: 542 - mask = MASK_DIO1; 543 - shift = SHIFT_DIO1; 544 - dio_addr = REG_DIOMAPPING1; 545 - break; 546 - case 2: 547 - mask = MASK_DIO2; 548 - shift = SHIFT_DIO2; 549 - dio_addr = REG_DIOMAPPING1; 550 - break; 551 - case 3: 552 - mask = MASK_DIO3; 553 - shift = SHIFT_DIO3; 554 - dio_addr = REG_DIOMAPPING1; 555 - break; 556 - case 4: 557 - mask = MASK_DIO4; 558 - shift = SHIFT_DIO4; 559 - dio_addr = REG_DIOMAPPING2; 560 - break; 561 - case 5: 562 - mask = MASK_DIO5; 563 - shift = SHIFT_DIO5; 564 - dio_addr = REG_DIOMAPPING2; 565 - break; 566 - default: 567 - dev_dbg(&spi->dev, "set: illegal dio number %u\n", dio_number); 568 - return -EINVAL; 569 - } 570 - 571 - // read reg 572 - dio_value = rf69_read_reg(spi, dio_addr); 573 - // delete old value 574 - dio_value = dio_value & ~mask; 575 - // add new value 576 - dio_value = dio_value | value << shift; 577 - // write back 578 - return rf69_write_reg(spi, dio_addr, dio_value); 579 - } 580 - 581 - int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold) 582 - { 583 - /* no value check needed - u8 exactly matches register size */ 584 - 585 - return rf69_write_reg(spi, REG_RSSITHRESH, threshold); 586 - } 587 - 588 - int rf69_set_preamble_length(struct spi_device *spi, u16 preamble_length) 589 - { 590 - int retval; 591 - u8 msb, lsb; 592 - 593 - /* no value check needed - u16 exactly matches register size */ 594 - 595 - /* calculate reg settings */ 596 - msb = (preamble_length & 0xff00) >> 8; 597 - lsb = (preamble_length & 0xff); 598 - 599 - /* transmit to chip */ 600 - retval = rf69_write_reg(spi, REG_PREAMBLE_MSB, msb); 601 - if (retval) 602 - return retval; 603 - return rf69_write_reg(spi, REG_PREAMBLE_LSB, lsb); 604 - } 605 - 606 - int rf69_enable_sync(struct spi_device *spi) 607 - { 608 - return rf69_set_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_SYNC_ON); 609 - } 610 - 611 - int rf69_disable_sync(struct spi_device *spi) 612 - { 613 - return rf69_clear_bit(spi, REG_SYNC_CONFIG, MASK_SYNC_CONFIG_SYNC_ON); 614 - } 615 - 616 - int rf69_set_fifo_fill_condition(struct spi_device *spi, 617 - enum fifo_fill_condition fifo_fill_condition) 618 - { 619 - switch (fifo_fill_condition) { 620 - case always: 621 - return rf69_set_bit(spi, REG_SYNC_CONFIG, 622 - MASK_SYNC_CONFIG_FIFO_FILL_CONDITION); 623 - case after_sync_interrupt: 624 - return rf69_clear_bit(spi, REG_SYNC_CONFIG, 625 - MASK_SYNC_CONFIG_FIFO_FILL_CONDITION); 626 - default: 627 - dev_dbg(&spi->dev, "set: illegal fifo fill condition %u\n", fifo_fill_condition); 628 - return -EINVAL; 629 - } 630 - } 631 - 632 - int rf69_set_sync_size(struct spi_device *spi, u8 sync_size) 633 - { 634 - // check input value 635 - if (sync_size > 0x07) { 636 - dev_dbg(&spi->dev, "set: illegal sync size %u\n", sync_size); 637 - return -EINVAL; 638 - } 639 - 640 - // write value 641 - return rf69_read_mod_write(spi, REG_SYNC_CONFIG, 642 - MASK_SYNC_CONFIG_SYNC_SIZE, 643 - (sync_size << 3)); 644 - } 645 - 646 - int rf69_set_sync_values(struct spi_device *spi, u8 sync_values[8]) 647 - { 648 - int retval = 0; 649 - 650 - retval += rf69_write_reg(spi, REG_SYNCVALUE1, sync_values[0]); 651 - retval += rf69_write_reg(spi, REG_SYNCVALUE2, sync_values[1]); 652 - retval += rf69_write_reg(spi, REG_SYNCVALUE3, sync_values[2]); 653 - retval += rf69_write_reg(spi, REG_SYNCVALUE4, sync_values[3]); 654 - retval += rf69_write_reg(spi, REG_SYNCVALUE5, sync_values[4]); 655 - retval += rf69_write_reg(spi, REG_SYNCVALUE6, sync_values[5]); 656 - retval += rf69_write_reg(spi, REG_SYNCVALUE7, sync_values[6]); 657 - retval += rf69_write_reg(spi, REG_SYNCVALUE8, sync_values[7]); 658 - 659 - return retval; 660 - } 661 - 662 - int rf69_set_packet_format(struct spi_device *spi, 663 - enum packet_format packet_format) 664 - { 665 - switch (packet_format) { 666 - case packet_length_var: 667 - return rf69_set_bit(spi, REG_PACKETCONFIG1, 668 - MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE); 669 - case packet_length_fix: 670 - return rf69_clear_bit(spi, REG_PACKETCONFIG1, 671 - MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE); 672 - default: 673 - dev_dbg(&spi->dev, "set: illegal packet format %u\n", packet_format); 674 - return -EINVAL; 675 - } 676 - } 677 - 678 - int rf69_enable_crc(struct spi_device *spi) 679 - { 680 - return rf69_set_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_CRC_ON); 681 - } 682 - 683 - int rf69_disable_crc(struct spi_device *spi) 684 - { 685 - return rf69_clear_bit(spi, REG_PACKETCONFIG1, MASK_PACKETCONFIG1_CRC_ON); 686 - } 687 - 688 - int rf69_set_address_filtering(struct spi_device *spi, 689 - enum address_filtering address_filtering) 690 - { 691 - static const u8 af_map[] = { 692 - [filtering_off] = PACKETCONFIG1_ADDRESSFILTERING_OFF, 693 - [node_address] = PACKETCONFIG1_ADDRESSFILTERING_NODE, 694 - [node_or_broadcast_address] = 695 - PACKETCONFIG1_ADDRESSFILTERING_NODEBROADCAST, 696 - }; 697 - 698 - if (unlikely(address_filtering >= ARRAY_SIZE(af_map))) { 699 - dev_dbg(&spi->dev, "set: illegal address filtering %u\n", address_filtering); 700 - return -EINVAL; 701 - } 702 - 703 - return rf69_read_mod_write(spi, REG_PACKETCONFIG1, 704 - MASK_PACKETCONFIG1_ADDRESSFILTERING, 705 - af_map[address_filtering]); 706 - } 707 - 708 - int rf69_set_payload_length(struct spi_device *spi, u8 payload_length) 709 - { 710 - return rf69_write_reg(spi, REG_PAYLOAD_LENGTH, payload_length); 711 - } 712 - 713 - int rf69_set_node_address(struct spi_device *spi, u8 node_address) 714 - { 715 - return rf69_write_reg(spi, REG_NODEADRS, node_address); 716 - } 717 - 718 - int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcast_address) 719 - { 720 - return rf69_write_reg(spi, REG_BROADCASTADRS, broadcast_address); 721 - } 722 - 723 - int rf69_set_tx_start_condition(struct spi_device *spi, 724 - enum tx_start_condition tx_start_condition) 725 - { 726 - switch (tx_start_condition) { 727 - case fifo_level: 728 - return rf69_clear_bit(spi, REG_FIFO_THRESH, 729 - MASK_FIFO_THRESH_TXSTART); 730 - case fifo_not_empty: 731 - return rf69_set_bit(spi, REG_FIFO_THRESH, 732 - MASK_FIFO_THRESH_TXSTART); 733 - default: 734 - dev_dbg(&spi->dev, "set: illegal tx start condition %u\n", tx_start_condition); 735 - return -EINVAL; 736 - } 737 - } 738 - 739 - int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold) 740 - { 741 - int retval; 742 - 743 - /* check input value */ 744 - if (threshold & ~MASK_FIFO_THRESH_VALUE) { 745 - dev_dbg(&spi->dev, "set: illegal fifo threshold %u\n", threshold); 746 - return -EINVAL; 747 - } 748 - 749 - /* write value */ 750 - retval = rf69_read_mod_write(spi, REG_FIFO_THRESH, 751 - MASK_FIFO_THRESH_VALUE, 752 - threshold); 753 - if (retval) 754 - return retval; 755 - 756 - /* 757 - * access the fifo to activate new threshold 758 - * retval (mis-) used as buffer here 759 - */ 760 - return rf69_read_fifo(spi, (u8 *)&retval, 1); 761 - } 762 - 763 - int rf69_set_dagc(struct spi_device *spi, enum dagc dagc) 764 - { 765 - static const u8 dagc_map[] = { 766 - [normal_mode] = DAGC_NORMAL, 767 - [improve] = DAGC_IMPROVED_LOWBETA0, 768 - [improve_for_low_modulation_index] = DAGC_IMPROVED_LOWBETA1, 769 - }; 770 - 771 - if (unlikely(dagc >= ARRAY_SIZE(dagc_map))) { 772 - dev_dbg(&spi->dev, "set: illegal dagc %u\n", dagc); 773 - return -EINVAL; 774 - } 775 - 776 - return rf69_write_reg(spi, REG_TESTDAGC, dagc_map[dagc]); 777 - } 778 - 779 - /*-------------------------------------------------------------------------*/ 780 - 781 - int rf69_read_fifo(struct spi_device *spi, u8 *buffer, unsigned int size) 782 - { 783 - int i; 784 - struct spi_transfer transfer; 785 - u8 local_buffer[FIFO_SIZE + 1] = {}; 786 - int retval; 787 - 788 - if (size > FIFO_SIZE) { 789 - dev_dbg(&spi->dev, 790 - "read fifo: passed in buffer bigger then internal buffer\n"); 791 - return -EMSGSIZE; 792 - } 793 - 794 - /* prepare a bidirectional transfer */ 795 - local_buffer[0] = REG_FIFO; 796 - memset(&transfer, 0, sizeof(transfer)); 797 - transfer.tx_buf = local_buffer; 798 - transfer.rx_buf = local_buffer; 799 - transfer.len = size + 1; 800 - 801 - retval = spi_sync_transfer(spi, &transfer, 1); 802 - 803 - /* print content read from fifo for debugging purposes */ 804 - for (i = 0; i < size; i++) 805 - dev_dbg(&spi->dev, "%d - 0x%x\n", i, local_buffer[i + 1]); 806 - 807 - memcpy(buffer, &local_buffer[1], size); 808 - 809 - return retval; 810 - } 811 - 812 - int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size) 813 - { 814 - int i; 815 - u8 local_buffer[FIFO_SIZE + 1]; 816 - 817 - if (size > FIFO_SIZE) { 818 - dev_dbg(&spi->dev, 819 - "write fifo: passed in buffer bigger then internal buffer\n"); 820 - return -EMSGSIZE; 821 - } 822 - 823 - local_buffer[0] = REG_FIFO | WRITE_BIT; 824 - memcpy(&local_buffer[1], buffer, size); 825 - 826 - /* print content written from fifo for debugging purposes */ 827 - for (i = 0; i < size; i++) 828 - dev_dbg(&spi->dev, "%d - 0x%x\n", i, buffer[i]); 829 - 830 - return spi_write(spi, local_buffer, size + 1); 831 - } 832 -
-66
drivers/staging/pi433/rf69.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * hardware abstraction/register access for HopeRf rf69 radio module 4 - * 5 - * Copyright (C) 2016 Wolf-Entwicklungen 6 - * Marcus Wolf <linux@wolf-entwicklungen.de> 7 - */ 8 - #ifndef RF69_H 9 - #define RF69_H 10 - 11 - #include "rf69_enum.h" 12 - #include "rf69_registers.h" 13 - 14 - #define FIFO_SIZE 66 /* bytes */ 15 - 16 - u8 rf69_read_reg(struct spi_device *spi, u8 addr); 17 - int rf69_get_version(struct spi_device *spi); 18 - int rf69_set_mode(struct spi_device *spi, enum mode mode); 19 - int rf69_set_data_mode(struct spi_device *spi, u8 data_mode); 20 - int rf69_set_modulation(struct spi_device *spi, enum modulation modulation); 21 - int rf69_set_modulation_shaping(struct spi_device *spi, 22 - enum mod_shaping mod_shaping); 23 - int rf69_set_bit_rate(struct spi_device *spi, u16 bit_rate); 24 - int rf69_set_deviation(struct spi_device *spi, u32 deviation); 25 - int rf69_set_frequency(struct spi_device *spi, u32 frequency); 26 - int rf69_enable_amplifier(struct spi_device *spi, u8 amplifier_mask); 27 - int rf69_disable_amplifier(struct spi_device *spi, u8 amplifier_mask); 28 - int rf69_set_output_power_level(struct spi_device *spi, u8 power_level); 29 - int rf69_set_pa_ramp(struct spi_device *spi, enum pa_ramp pa_ramp); 30 - int rf69_set_antenna_impedance(struct spi_device *spi, 31 - enum antenna_impedance antenna_impedance); 32 - int rf69_set_lna_gain(struct spi_device *spi, enum lna_gain lna_gain); 33 - int rf69_set_bandwidth(struct spi_device *spi, enum mantisse mantisse, 34 - u8 exponent); 35 - int rf69_set_bandwidth_during_afc(struct spi_device *spi, 36 - enum mantisse mantisse, 37 - u8 exponent); 38 - int rf69_set_ook_threshold_dec(struct spi_device *spi, 39 - enum threshold_decrement threshold_decrement); 40 - int rf69_set_dio_mapping(struct spi_device *spi, u8 dio_number, u8 value); 41 - int rf69_set_rssi_threshold(struct spi_device *spi, u8 threshold); 42 - int rf69_set_preamble_length(struct spi_device *spi, u16 preamble_length); 43 - int rf69_enable_sync(struct spi_device *spi); 44 - int rf69_disable_sync(struct spi_device *spi); 45 - int rf69_set_fifo_fill_condition(struct spi_device *spi, 46 - enum fifo_fill_condition fifo_fill_condition); 47 - int rf69_set_sync_size(struct spi_device *spi, u8 sync_size); 48 - int rf69_set_sync_values(struct spi_device *spi, u8 sync_values[8]); 49 - int rf69_set_packet_format(struct spi_device *spi, 50 - enum packet_format packet_format); 51 - int rf69_enable_crc(struct spi_device *spi); 52 - int rf69_disable_crc(struct spi_device *spi); 53 - int rf69_set_address_filtering(struct spi_device *spi, 54 - enum address_filtering address_filtering); 55 - int rf69_set_payload_length(struct spi_device *spi, u8 payload_length); 56 - int rf69_set_node_address(struct spi_device *spi, u8 node_address); 57 - int rf69_set_broadcast_address(struct spi_device *spi, u8 broadcast_address); 58 - int rf69_set_tx_start_condition(struct spi_device *spi, 59 - enum tx_start_condition tx_start_condition); 60 - int rf69_set_fifo_threshold(struct spi_device *spi, u8 threshold); 61 - int rf69_set_dagc(struct spi_device *spi, enum dagc dagc); 62 - 63 - int rf69_read_fifo(struct spi_device *spi, u8 *buffer, unsigned int size); 64 - int rf69_write_fifo(struct spi_device *spi, u8 *buffer, unsigned int size); 65 - 66 - #endif
-126
drivers/staging/pi433/rf69_enum.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * enumerations for HopeRf rf69 radio module 4 - * 5 - * Copyright (C) 2016 Wolf-Entwicklungen 6 - * Marcus Wolf <linux@wolf-entwicklungen.de> 7 - */ 8 - 9 - #ifndef RF69_ENUM_H 10 - #define RF69_ENUM_H 11 - 12 - enum mode { 13 - mode_sleep, 14 - standby, 15 - synthesizer, 16 - transmit, 17 - receive 18 - }; 19 - 20 - enum modulation { 21 - OOK, 22 - FSK, 23 - UNDEF 24 - }; 25 - 26 - enum mod_shaping { 27 - SHAPING_OFF, 28 - SHAPING_1_0, 29 - SHAPING_0_5, 30 - SHAPING_0_3, 31 - SHAPING_BR, 32 - SHAPING_2BR 33 - }; 34 - 35 - enum pa_ramp { 36 - ramp3400, 37 - ramp2000, 38 - ramp1000, 39 - ramp500, 40 - ramp250, 41 - ramp125, 42 - ramp100, 43 - ramp62, 44 - ramp50, 45 - ramp40, 46 - ramp31, 47 - ramp25, 48 - ramp20, 49 - ramp15, 50 - ramp12, 51 - ramp10 52 - }; 53 - 54 - enum antenna_impedance { 55 - fifty_ohm, 56 - two_hundred_ohm 57 - }; 58 - 59 - enum lna_gain { 60 - automatic, 61 - max, 62 - max_minus_6, 63 - max_minus_12, 64 - max_minus_24, 65 - max_minus_36, 66 - max_minus_48, 67 - undefined 68 - }; 69 - 70 - enum mantisse { 71 - mantisse16, 72 - mantisse20, 73 - mantisse24 74 - }; 75 - 76 - enum threshold_decrement { 77 - dec_every8th, 78 - dec_every4th, 79 - dec_every2nd, 80 - dec_once, 81 - dec_twice, 82 - dec_4times, 83 - dec_8times, 84 - dec_16times 85 - }; 86 - 87 - enum fifo_fill_condition { 88 - after_sync_interrupt, 89 - always 90 - }; 91 - 92 - enum packet_format { 93 - /* 94 - * Used when the size of payload is fixed in advance. This mode of 95 - * operation may be of interest to minimize RF overhead by 1 byte as 96 - * no length byte field is required 97 - */ 98 - packet_length_fix, 99 - /* 100 - * Used when the size of payload isn't known in advance. It requires the 101 - * transmitter to send the length byte in each packet so the receiver 102 - * would know how to operate properly 103 - */ 104 - packet_length_var 105 - }; 106 - 107 - enum tx_start_condition { 108 - /* the number of bytes in the FIFO exceeds FIFO_THRESHOLD */ 109 - fifo_level, 110 - /* at least one byte in the FIFO */ 111 - fifo_not_empty 112 - }; 113 - 114 - enum address_filtering { 115 - filtering_off, 116 - node_address, 117 - node_or_broadcast_address 118 - }; 119 - 120 - enum dagc { 121 - normal_mode, 122 - improve, 123 - improve_for_low_modulation_index 124 - }; 125 - 126 - #endif
-478
drivers/staging/pi433/rf69_registers.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0+ */ 2 - /* 3 - * register description for HopeRf rf69 radio module 4 - * 5 - * Copyright (C) 2016 Wolf-Entwicklungen 6 - * Marcus Wolf <linux@wolf-entwicklungen.de> 7 - */ 8 - 9 - /*******************************************/ 10 - /* RF69 register addresses */ 11 - /*******************************************/ 12 - #define REG_FIFO 0x00 13 - #define REG_OPMODE 0x01 14 - #define REG_DATAMODUL 0x02 15 - #define REG_BITRATE_MSB 0x03 16 - #define REG_BITRATE_LSB 0x04 17 - #define REG_FDEV_MSB 0x05 18 - #define REG_FDEV_LSB 0x06 19 - #define REG_FRF_MSB 0x07 20 - #define REG_FRF_MID 0x08 21 - #define REG_FRF_LSB 0x09 22 - #define REG_OSC1 0x0A 23 - #define REG_AFCCTRL 0x0B 24 - #define REG_LOWBAT 0x0C 25 - #define REG_LISTEN1 0x0D 26 - #define REG_LISTEN2 0x0E 27 - #define REG_LISTEN3 0x0F 28 - #define REG_VERSION 0x10 29 - #define REG_PALEVEL 0x11 30 - #define REG_PARAMP 0x12 31 - #define REG_OCP 0x13 32 - #define REG_AGCREF 0x14 /* not available on RF69 */ 33 - #define REG_AGCTHRESH1 0x15 /* not available on RF69 */ 34 - #define REG_AGCTHRESH2 0x16 /* not available on RF69 */ 35 - #define REG_AGCTHRESH3 0x17 /* not available on RF69 */ 36 - #define REG_LNA 0x18 37 - #define REG_RXBW 0x19 38 - #define REG_AFCBW 0x1A 39 - #define REG_OOKPEAK 0x1B 40 - #define REG_OOKAVG 0x1C 41 - #define REG_OOKFIX 0x1D 42 - #define REG_AFCFEI 0x1E 43 - #define REG_AFCMSB 0x1F 44 - #define REG_AFCLSB 0x20 45 - #define REG_FEIMSB 0x21 46 - #define REG_FEILSB 0x22 47 - #define REG_RSSICONFIG 0x23 48 - #define REG_RSSIVALUE 0x24 49 - #define REG_DIOMAPPING1 0x25 50 - #define REG_DIOMAPPING2 0x26 51 - #define REG_IRQFLAGS1 0x27 52 - #define REG_IRQFLAGS2 0x28 53 - #define REG_RSSITHRESH 0x29 54 - #define REG_RXTIMEOUT1 0x2A 55 - #define REG_RXTIMEOUT2 0x2B 56 - #define REG_PREAMBLE_MSB 0x2C 57 - #define REG_PREAMBLE_LSB 0x2D 58 - #define REG_SYNC_CONFIG 0x2E 59 - #define REG_SYNCVALUE1 0x2F 60 - #define REG_SYNCVALUE2 0x30 61 - #define REG_SYNCVALUE3 0x31 62 - #define REG_SYNCVALUE4 0x32 63 - #define REG_SYNCVALUE5 0x33 64 - #define REG_SYNCVALUE6 0x34 65 - #define REG_SYNCVALUE7 0x35 66 - #define REG_SYNCVALUE8 0x36 67 - #define REG_PACKETCONFIG1 0x37 68 - #define REG_PAYLOAD_LENGTH 0x38 69 - #define REG_NODEADRS 0x39 70 - #define REG_BROADCASTADRS 0x3A 71 - #define REG_AUTOMODES 0x3B 72 - #define REG_FIFO_THRESH 0x3C 73 - #define REG_PACKETCONFIG2 0x3D 74 - #define REG_AESKEY1 0x3E 75 - #define REG_AESKEY2 0x3F 76 - #define REG_AESKEY3 0x40 77 - #define REG_AESKEY4 0x41 78 - #define REG_AESKEY5 0x42 79 - #define REG_AESKEY6 0x43 80 - #define REG_AESKEY7 0x44 81 - #define REG_AESKEY8 0x45 82 - #define REG_AESKEY9 0x46 83 - #define REG_AESKEY10 0x47 84 - #define REG_AESKEY11 0x48 85 - #define REG_AESKEY12 0x49 86 - #define REG_AESKEY13 0x4A 87 - #define REG_AESKEY14 0x4B 88 - #define REG_AESKEY15 0x4C 89 - #define REG_AESKEY16 0x4D 90 - #define REG_TEMP1 0x4E 91 - #define REG_TEMP2 0x4F 92 - #define REG_TESTLNA 0x58 93 - #define REG_TESTPA1 0x5A /* only present on RFM69HW */ 94 - #define REG_TESTPA2 0x5C /* only present on RFM69HW */ 95 - #define REG_TESTDAGC 0x6F 96 - #define REG_TESTAFC 0x71 97 - 98 - /******************************************************/ 99 - /* RF69/SX1231 bit definition */ 100 - /******************************************************/ 101 - /* write bit */ 102 - #define WRITE_BIT 0x80 103 - 104 - /* RegOpMode */ 105 - #define MASK_OPMODE_SEQUENCER_OFF 0x80 106 - #define MASK_OPMODE_LISTEN_ON 0x40 107 - #define MASK_OPMODE_LISTEN_ABORT 0x20 108 - #define MASK_OPMODE_MODE 0x1C 109 - 110 - #define OPMODE_MODE_SLEEP 0x00 111 - #define OPMODE_MODE_STANDBY 0x04 /* default */ 112 - #define OPMODE_MODE_SYNTHESIZER 0x08 113 - #define OPMODE_MODE_TRANSMIT 0x0C 114 - #define OPMODE_MODE_RECEIVE 0x10 115 - 116 - /* RegDataModul */ 117 - #define MASK_DATAMODUL_MODE 0x06 118 - #define MASK_DATAMODUL_MODULATION_TYPE 0x18 119 - #define MASK_DATAMODUL_MODULATION_SHAPE 0x03 120 - 121 - #define DATAMODUL_MODE_PACKET 0x00 /* default */ 122 - #define DATAMODUL_MODE_CONTINUOUS 0x40 123 - #define DATAMODUL_MODE_CONTINUOUS_NOSYNC 0x60 124 - 125 - #define DATAMODUL_MODULATION_TYPE_FSK 0x00 /* default */ 126 - #define DATAMODUL_MODULATION_TYPE_OOK 0x08 127 - 128 - #define DATAMODUL_MODULATION_SHAPE_NONE 0x00 /* default */ 129 - #define DATAMODUL_MODULATION_SHAPE_1_0 0x01 130 - #define DATAMODUL_MODULATION_SHAPE_0_5 0x02 131 - #define DATAMODUL_MODULATION_SHAPE_0_3 0x03 132 - #define DATAMODUL_MODULATION_SHAPE_BR 0x01 133 - #define DATAMODUL_MODULATION_SHAPE_2BR 0x02 134 - 135 - /* RegFDevMsb (0x05)*/ 136 - #define FDEVMASB_MASK 0x3f 137 - 138 - /* 139 - * // RegOsc1 140 - * #define OSC1_RCCAL_START 0x80 141 - * #define OSC1_RCCAL_DONE 0x40 142 - * 143 - * // RegLowBat 144 - * #define LOWBAT_MONITOR 0x10 145 - * #define LOWBAT_ON 0x08 146 - * #define LOWBAT_OFF 0x00 // Default 147 - * 148 - * #define LOWBAT_TRIM_1695 0x00 149 - * #define LOWBAT_TRIM_1764 0x01 150 - * #define LOWBAT_TRIM_1835 0x02 // Default 151 - * #define LOWBAT_TRIM_1905 0x03 152 - * #define LOWBAT_TRIM_1976 0x04 153 - * #define LOWBAT_TRIM_2045 0x05 154 - * #define LOWBAT_TRIM_2116 0x06 155 - * #define LOWBAT_TRIM_2185 0x07 156 - * 157 - * 158 - * // RegListen1 159 - * #define LISTEN1_RESOL_64 0x50 160 - * #define LISTEN1_RESOL_4100 0xA0 // Default 161 - * #define LISTEN1_RESOL_262000 0xF0 162 - * 163 - * #define LISTEN1_CRITERIA_RSSI 0x00 // Default 164 - * #define LISTEN1_CRITERIA_RSSIANDSYNC 0x08 165 - * 166 - * #define LISTEN1_END_00 0x00 167 - * #define LISTEN1_END_01 0x02 // Default 168 - * #define LISTEN1_END_10 0x04 169 - * 170 - * 171 - * // RegListen2 172 - * #define LISTEN2_COEFIDLE_VALUE 0xF5 // Default 173 - * 174 - * // RegListen3 175 - * #define LISTEN3_COEFRX_VALUE 0x20 // Default 176 - */ 177 - 178 - // RegPaLevel 179 - #define MASK_PALEVEL_PA0 0x80 180 - #define MASK_PALEVEL_PA1 0x40 181 - #define MASK_PALEVEL_PA2 0x20 182 - #define MASK_PALEVEL_OUTPUT_POWER 0x1F 183 - 184 - // RegPaRamp 185 - #define PARAMP_3400 0x00 186 - #define PARAMP_2000 0x01 187 - #define PARAMP_1000 0x02 188 - #define PARAMP_500 0x03 189 - #define PARAMP_250 0x04 190 - #define PARAMP_125 0x05 191 - #define PARAMP_100 0x06 192 - #define PARAMP_62 0x07 193 - #define PARAMP_50 0x08 194 - #define PARAMP_40 0x09 /* default */ 195 - #define PARAMP_31 0x0A 196 - #define PARAMP_25 0x0B 197 - #define PARAMP_20 0x0C 198 - #define PARAMP_15 0x0D 199 - #define PARAMP_12 0x0E 200 - #define PARAMP_10 0x0F 201 - 202 - #define MASK_PARAMP 0x0F 203 - 204 - /* 205 - * // RegOcp 206 - * #define OCP_OFF 0x0F 207 - * #define OCP_ON 0x1A // Default 208 - * 209 - * #define OCP_TRIM_45 0x00 210 - * #define OCP_TRIM_50 0x01 211 - * #define OCP_TRIM_55 0x02 212 - * #define OCP_TRIM_60 0x03 213 - * #define OCP_TRIM_65 0x04 214 - * #define OCP_TRIM_70 0x05 215 - * #define OCP_TRIM_75 0x06 216 - * #define OCP_TRIM_80 0x07 217 - * #define OCP_TRIM_85 0x08 218 - * #define OCP_TRIM_90 0x09 219 - * #define OCP_TRIM_95 0x0A 220 - * #define OCP_TRIM_100 0x0B // Default 221 - * #define OCP_TRIM_105 0x0C 222 - * #define OCP_TRIM_110 0x0D 223 - * #define OCP_TRIM_115 0x0E 224 - * #define OCP_TRIM_120 0x0F 225 - */ 226 - 227 - /* RegLna (0x18) */ 228 - #define MASK_LNA_ZIN 0x80 229 - #define MASK_LNA_CURRENT_GAIN 0x38 230 - #define MASK_LNA_GAIN 0x07 231 - 232 - #define LNA_GAIN_AUTO 0x00 /* default */ 233 - #define LNA_GAIN_MAX 0x01 234 - #define LNA_GAIN_MAX_MINUS_6 0x02 235 - #define LNA_GAIN_MAX_MINUS_12 0x03 236 - #define LNA_GAIN_MAX_MINUS_24 0x04 237 - #define LNA_GAIN_MAX_MINUS_36 0x05 238 - #define LNA_GAIN_MAX_MINUS_48 0x06 239 - 240 - /* RegRxBw (0x19) and RegAfcBw (0x1A) */ 241 - #define MASK_BW_DCC_FREQ 0xE0 242 - #define MASK_BW_MANTISSE 0x18 243 - #define MASK_BW_EXPONENT 0x07 244 - 245 - #define BW_DCC_16_PERCENT 0x00 246 - #define BW_DCC_8_PERCENT 0x20 247 - #define BW_DCC_4_PERCENT 0x40 /* default */ 248 - #define BW_DCC_2_PERCENT 0x60 249 - #define BW_DCC_1_PERCENT 0x80 250 - #define BW_DCC_0_5_PERCENT 0xA0 251 - #define BW_DCC_0_25_PERCENT 0xC0 252 - #define BW_DCC_0_125_PERCENT 0xE0 253 - 254 - #define BW_MANT_16 0x00 255 - #define BW_MANT_20 0x08 256 - #define BW_MANT_24 0x10 /* default */ 257 - 258 - /* RegOokPeak (0x1B) */ 259 - #define MASK_OOKPEAK_THRESTYPE 0xc0 260 - #define MASK_OOKPEAK_THRESSTEP 0x38 261 - #define MASK_OOKPEAK_THRESDEC 0x07 262 - 263 - #define OOKPEAK_THRESHTYPE_FIXED 0x00 264 - #define OOKPEAK_THRESHTYPE_PEAK 0x40 /* default */ 265 - #define OOKPEAK_THRESHTYPE_AVERAGE 0x80 266 - 267 - #define OOKPEAK_THRESHSTEP_0_5_DB 0x00 /* default */ 268 - #define OOKPEAK_THRESHSTEP_1_0_DB 0x08 269 - #define OOKPEAK_THRESHSTEP_1_5_DB 0x10 270 - #define OOKPEAK_THRESHSTEP_2_0_DB 0x18 271 - #define OOKPEAK_THRESHSTEP_3_0_DB 0x20 272 - #define OOKPEAK_THRESHSTEP_4_0_DB 0x28 273 - #define OOKPEAK_THRESHSTEP_5_0_DB 0x30 274 - #define OOKPEAK_THRESHSTEP_6_0_DB 0x38 275 - 276 - #define OOKPEAK_THRESHDEC_ONCE 0x00 /* default */ 277 - #define OOKPEAK_THRESHDEC_EVERY_2ND 0x01 278 - #define OOKPEAK_THRESHDEC_EVERY_4TH 0x02 279 - #define OOKPEAK_THRESHDEC_EVERY_8TH 0x03 280 - #define OOKPEAK_THRESHDEC_TWICE 0x04 281 - #define OOKPEAK_THRESHDEC_4_TIMES 0x05 282 - #define OOKPEAK_THRESHDEC_8_TIMES 0x06 283 - #define OOKPEAK_THRESHDEC_16_TIMES 0x07 284 - 285 - /* 286 - * // RegOokAvg 287 - * #define OOKAVG_AVERAGETHRESHFILT_00 0x00 288 - * #define OOKAVG_AVERAGETHRESHFILT_01 0x40 289 - * #define OOKAVG_AVERAGETHRESHFILT_10 0x80 // Default 290 - * #define OOKAVG_AVERAGETHRESHFILT_11 0xC0 291 - * 292 - * 293 - * // RegAfcFei 294 - * #define AFCFEI_FEI_DONE 0x40 295 - * #define AFCFEI_FEI_START 0x20 296 - * #define AFCFEI_AFC_DONE 0x10 297 - * #define AFCFEI_AFCAUTOCLEAR_ON 0x08 298 - * #define AFCFEI_AFCAUTOCLEAR_OFF 0x00 // Default 299 - * 300 - * #define AFCFEI_AFCAUTO_ON 0x04 301 - * #define AFCFEI_AFCAUTO_OFF 0x00 // Default 302 - * 303 - * #define AFCFEI_AFC_CLEAR 0x02 304 - * #define AFCFEI_AFC_START 0x01 305 - * 306 - * // RegRssiConfig 307 - * #define RSSI_FASTRX_ON 0x08 308 - * #define RSSI_FASTRX_OFF 0x00 // Default 309 - * #define RSSI_DONE 0x02 310 - * #define RSSI_START 0x01 311 - */ 312 - 313 - /* RegDioMapping1 */ 314 - #define MASK_DIO0 0xC0 315 - #define MASK_DIO1 0x30 316 - #define MASK_DIO2 0x0C 317 - #define MASK_DIO3 0x03 318 - #define SHIFT_DIO0 6 319 - #define SHIFT_DIO1 4 320 - #define SHIFT_DIO2 2 321 - #define SHIFT_DIO3 0 322 - 323 - /* RegDioMapping2 */ 324 - #define MASK_DIO4 0xC0 325 - #define MASK_DIO5 0x30 326 - #define SHIFT_DIO4 6 327 - #define SHIFT_DIO5 4 328 - 329 - /* DIO numbers */ 330 - #define DIO0 0 331 - #define DIO1 1 332 - #define DIO2 2 333 - #define DIO3 3 334 - #define DIO4 4 335 - #define DIO5 5 336 - 337 - /* DIO Mapping values (packet mode) */ 338 - #define DIO_MODE_READY_DIO4 0x00 339 - #define DIO_MODE_READY_DIO5 0x03 340 - #define DIO_CLK_OUT 0x00 341 - #define DIO_DATA 0x01 342 - #define DIO_TIMEOUT_DIO1 0x03 343 - #define DIO_TIMEOUT_DIO4 0x00 344 - #define DIO_RSSI_DIO0 0x03 345 - #define DIO_RSSI_DIO3_4 0x01 346 - #define DIO_RX_READY 0x02 347 - #define DIO_PLL_LOCK 0x03 348 - #define DIO_TX_READY 0x01 349 - #define DIO_FIFO_FULL_DIO1 0x01 350 - #define DIO_FIFO_FULL_DIO3 0x00 351 - #define DIO_SYNC_ADDRESS 0x02 352 - #define DIO_FIFO_NOT_EMPTY_DIO1 0x02 353 - #define DIO_FIFO_NOT_EMPTY_FIO2 0x00 354 - #define DIO_AUTOMODE 0x04 355 - #define DIO_FIFO_LEVEL 0x00 356 - #define DIO_CRC_OK 0x00 357 - #define DIO_PAYLOAD_READY 0x01 358 - #define DIO_PACKET_SENT 0x00 359 - #define DIO_DCLK 0x00 360 - 361 - /* RegDioMapping2 CLK_OUT part */ 362 - #define MASK_DIOMAPPING2_CLK_OUT 0x07 363 - 364 - #define DIOMAPPING2_CLK_OUT_NO_DIV 0x00 365 - #define DIOMAPPING2_CLK_OUT_DIV_2 0x01 366 - #define DIOMAPPING2_CLK_OUT_DIV_4 0x02 367 - #define DIOMAPPING2_CLK_OUT_DIV_8 0x03 368 - #define DIOMAPPING2_CLK_OUT_DIV_16 0x04 369 - #define DIOMAPPING2_CLK_OUT_DIV_32 0x05 370 - #define DIOMAPPING2_CLK_OUT_RC 0x06 371 - #define DIOMAPPING2_CLK_OUT_OFF 0x07 /* default */ 372 - 373 - /* RegIrqFlags1 */ 374 - #define MASK_IRQFLAGS1_MODE_READY 0x80 375 - #define MASK_IRQFLAGS1_RX_READY 0x40 376 - #define MASK_IRQFLAGS1_TX_READY 0x20 377 - #define MASK_IRQFLAGS1_PLL_LOCK 0x10 378 - #define MASK_IRQFLAGS1_RSSI 0x08 379 - #define MASK_IRQFLAGS1_TIMEOUT 0x04 380 - #define MASK_IRQFLAGS1_AUTOMODE 0x02 381 - #define MASK_IRQFLAGS1_SYNC_ADDRESS_MATCH 0x01 382 - 383 - /* RegIrqFlags2 */ 384 - #define MASK_IRQFLAGS2_FIFO_FULL 0x80 385 - #define MASK_IRQFLAGS2_FIFO_NOT_EMPTY 0x40 386 - #define MASK_IRQFLAGS2_FIFO_LEVEL 0x20 387 - #define MASK_IRQFLAGS2_FIFO_OVERRUN 0x10 388 - #define MASK_IRQFLAGS2_PACKET_SENT 0x08 389 - #define MASK_IRQFLAGS2_PAYLOAD_READY 0x04 390 - #define MASK_IRQFLAGS2_CRC_OK 0x02 391 - #define MASK_IRQFLAGS2_LOW_BAT 0x01 392 - 393 - /* RegSyncConfig */ 394 - #define MASK_SYNC_CONFIG_SYNC_ON 0x80 /* default */ 395 - #define MASK_SYNC_CONFIG_FIFO_FILL_CONDITION 0x40 396 - #define MASK_SYNC_CONFIG_SYNC_SIZE 0x38 397 - #define MASK_SYNC_CONFIG_SYNC_TOLERANCE 0x07 398 - 399 - /* RegPacketConfig1 */ 400 - #define MASK_PACKETCONFIG1_PACKET_FORMAT_VARIABLE 0x80 401 - #define MASK_PACKETCONFIG1_DCFREE 0x60 402 - #define MASK_PACKETCONFIG1_CRC_ON 0x10 /* default */ 403 - #define MASK_PACKETCONFIG1_CRCAUTOCLEAR_OFF 0x08 404 - #define MASK_PACKETCONFIG1_ADDRESSFILTERING 0x06 405 - 406 - #define PACKETCONFIG1_DCFREE_OFF 0x00 /* default */ 407 - #define PACKETCONFIG1_DCFREE_MANCHESTER 0x20 408 - #define PACKETCONFIG1_DCFREE_WHITENING 0x40 409 - #define PACKETCONFIG1_ADDRESSFILTERING_OFF 0x00 /* default */ 410 - #define PACKETCONFIG1_ADDRESSFILTERING_NODE 0x02 411 - #define PACKETCONFIG1_ADDRESSFILTERING_NODEBROADCAST 0x04 412 - 413 - /* 414 - * // RegAutoModes 415 - * #define AUTOMODES_ENTER_OFF 0x00 // Default 416 - * #define AUTOMODES_ENTER_FIFONOTEMPTY 0x20 417 - * #define AUTOMODES_ENTER_FIFOLEVEL 0x40 418 - * #define AUTOMODES_ENTER_CRCOK 0x60 419 - * #define AUTOMODES_ENTER_PAYLOADREADY 0x80 420 - * #define AUTOMODES_ENTER_SYNCADRSMATCH 0xA0 421 - * #define AUTOMODES_ENTER_PACKETSENT 0xC0 422 - * #define AUTOMODES_ENTER_FIFOEMPTY 0xE0 423 - * 424 - * #define AUTOMODES_EXIT_OFF 0x00 // Default 425 - * #define AUTOMODES_EXIT_FIFOEMPTY 0x04 426 - * #define AUTOMODES_EXIT_FIFOLEVEL 0x08 427 - * #define AUTOMODES_EXIT_CRCOK 0x0C 428 - * #define AUTOMODES_EXIT_PAYLOADREADY 0x10 429 - * #define AUTOMODES_EXIT_SYNCADRSMATCH 0x14 430 - * #define AUTOMODES_EXIT_PACKETSENT 0x18 431 - * #define AUTOMODES_EXIT_RXTIMEOUT 0x1C 432 - * 433 - * #define AUTOMODES_INTERMEDIATE_SLEEP 0x00 // Default 434 - * #define AUTOMODES_INTERMEDIATE_STANDBY 0x01 435 - * #define AUTOMODES_INTERMEDIATE_RECEIVER 0x02 436 - * #define AUTOMODES_INTERMEDIATE_TRANSMITTER 0x03 437 - * 438 - */ 439 - /* RegFifoThresh (0x3c) */ 440 - #define MASK_FIFO_THRESH_TXSTART 0x80 441 - #define MASK_FIFO_THRESH_VALUE 0x7F 442 - 443 - /* 444 - * 445 - * // RegPacketConfig2 446 - * #define PACKET2_RXRESTARTDELAY_1BIT 0x00 // Default 447 - * #define PACKET2_RXRESTARTDELAY_2BITS 0x10 448 - * #define PACKET2_RXRESTARTDELAY_4BITS 0x20 449 - * #define PACKET2_RXRESTARTDELAY_8BITS 0x30 450 - * #define PACKET2_RXRESTARTDELAY_16BITS 0x40 451 - * #define PACKET2_RXRESTARTDELAY_32BITS 0x50 452 - * #define PACKET2_RXRESTARTDELAY_64BITS 0x60 453 - * #define PACKET2_RXRESTARTDELAY_128BITS 0x70 454 - * #define PACKET2_RXRESTARTDELAY_256BITS 0x80 455 - * #define PACKET2_RXRESTARTDELAY_512BITS 0x90 456 - * #define PACKET2_RXRESTARTDELAY_1024BITS 0xA0 457 - * #define PACKET2_RXRESTARTDELAY_2048BITS 0xB0 458 - * #define PACKET2_RXRESTARTDELAY_NONE 0xC0 459 - * #define PACKET2_RXRESTART 0x04 460 - * 461 - * #define PACKET2_AUTORXRESTART_ON 0x02 // Default 462 - * #define PACKET2_AUTORXRESTART_OFF 0x00 463 - * 464 - * #define PACKET2_AES_ON 0x01 465 - * #define PACKET2_AES_OFF 0x00 // Default 466 - * 467 - * 468 - * // RegTemp1 469 - * #define TEMP1_MEAS_START 0x08 470 - * #define TEMP1_MEAS_RUNNING 0x04 471 - * #define TEMP1_ADCLOWPOWER_ON 0x01 // Default 472 - * #define TEMP1_ADCLOWPOWER_OFF 0x00 473 - */ 474 - 475 - // RegTestDagc (0x6F) 476 - #define DAGC_NORMAL 0x00 /* Reset value */ 477 - #define DAGC_IMPROVED_LOWBETA1 0x20 478 - #define DAGC_IMPROVED_LOWBETA0 0x30 /* Recommended val */
+4 -7
drivers/staging/rtl8192e/rtl8192e/r8192E_cmdpkt.c
··· 11 11 bool rtl92e_send_cmd_pkt(struct net_device *dev, u32 type, const void *data, 12 12 u32 len) 13 13 { 14 - bool rt_status = true; 15 14 struct r8192_priv *priv = rtllib_priv(dev); 16 15 u16 frag_length = 0, frag_offset = 0; 17 16 struct sk_buff *skb; ··· 36 37 else 37 38 skb = dev_alloc_skb(frag_length + 4); 38 39 39 - if (!skb) { 40 - rt_status = false; 41 - goto Failed; 42 - } 40 + if (!skb) 41 + return false; 43 42 44 43 memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); 45 44 tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); ··· 74 77 } while (frag_offset < len); 75 78 76 79 rtl92e_writeb(dev, TP_POLL, TP_POLL_CQ); 77 - Failed: 78 - return rt_status; 80 + 81 + return true; 79 82 }
+8 -8
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c
··· 130 130 &priv->rtllib->current_network.qos_data.parameters; 131 131 132 132 u1bAIFS = qop->aifs[pAcParam] * 133 - ((mode & (WIRELESS_MODE_G | WIRELESS_MODE_N_24G)) ? 9 : 20) + aSifsTime; 133 + ((mode & (WIRELESS_MODE_G | WIRELESS_MODE_N_24G)) ? 9 : 20) + asifs_time; 134 134 135 135 rtl92e_dm_init_edca_turbo(dev); 136 136 ··· 702 702 } 703 703 } 704 704 705 - void rtl92e_set_monitor_mode(struct net_device *dev, bool bAllowAllDA, 706 - bool WriteIntoReg) 705 + void rtl92e_set_monitor_mode(struct net_device *dev, bool allow_all_da, 706 + bool write_into_reg) 707 707 { 708 708 struct r8192_priv *priv = rtllib_priv(dev); 709 709 710 - if (bAllowAllDA) 710 + if (allow_all_da) 711 711 priv->receive_config |= RCR_AAP; 712 712 else 713 713 priv->receive_config &= ~RCR_AAP; 714 714 715 - if (WriteIntoReg) 715 + if (write_into_reg) 716 716 rtl92e_writel(dev, RCR, priv->receive_config); 717 717 } 718 718 ··· 900 900 pTxFwInfo->RtsBandwidth = 0; 901 901 pTxFwInfo->RtsSubcarrier = cb_desc->RTSSC; 902 902 pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT == 0) ? 903 - (cb_desc->bRTSUseShortPreamble ? 1 : 0) : 903 + (cb_desc->rts_use_short_preamble ? 1 : 0) : 904 904 (cb_desc->bRTSUseShortGI ? 1 : 0); 905 905 if (priv->current_chnl_bw == HT_CHANNEL_WIDTH_20_40) { 906 906 if (cb_desc->bPacketBW) { ··· 1659 1659 stats->bFirstMPDU = (pDrvInfo->PartAggr == 1) && 1660 1660 (pDrvInfo->FirstAGGR == 1); 1661 1661 1662 - stats->TimeStampLow = pDrvInfo->TSFL; 1663 - stats->TimeStampHigh = rtl92e_readl(dev, TSFR + 4); 1662 + stats->time_stamp_low = pDrvInfo->TSFL; 1663 + stats->time_stamp_high = rtl92e_readl(dev, TSFR + 4); 1664 1664 1665 1665 _rtl92e_translate_rx_signal_stats(dev, skb, stats, pdesc, pDrvInfo); 1666 1666 skb_trim(skb, skb->len - S_CRC_LEN);
+2 -2
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.h
··· 21 21 void rtl92e_get_eeprom_size(struct net_device *dev); 22 22 bool rtl92e_start_adapter(struct net_device *dev); 23 23 void rtl92e_link_change(struct net_device *dev); 24 - void rtl92e_set_monitor_mode(struct net_device *dev, bool bAllowAllDA, 25 - bool WriteIntoReg); 24 + void rtl92e_set_monitor_mode(struct net_device *dev, bool allow_all_da, 25 + bool write_into_reg); 26 26 void rtl92e_fill_tx_desc(struct net_device *dev, struct tx_desc *pdesc, 27 27 struct cb_desc *cb_desc, struct sk_buff *skb); 28 28 void rtl92e_fill_tx_cmd_desc(struct net_device *dev, struct tx_desc_cmd *entry,
+1 -1
drivers/staging/rtl8192e/rtl8192e/rtl_core.c
··· 964 964 MAC80211_NOLINK) && 965 965 (ieee->rf_power_state == rf_on) && !ieee->is_set_key && 966 966 (!ieee->proto_stoppping) && !ieee->wx_set_enc) { 967 - if (ieee->pwr_save_ctrl.ReturnPoint == IPS_CALLBACK_NONE) 967 + if (ieee->pwr_save_ctrl.return_point == IPS_CALLBACK_NONE) 968 968 rtl92e_ips_enter(dev); 969 969 } 970 970 }
+2 -8
drivers/staging/rtl8192e/rtl8192e/rtl_dm.c
··· 144 144 /*------------------------Define global variable-----------------------------*/ 145 145 struct dig_t dm_digtable; 146 146 147 - struct drx_path_sel dm_rx_path_sel_table; 147 + static struct drx_path_sel dm_rx_path_sel_table; 148 148 /*------------------------Define global variable-----------------------------*/ 149 149 150 150 ··· 163 163 164 164 static void _rtl92e_dm_dig_init(struct net_device *dev); 165 165 static void _rtl92e_dm_ctrl_initgain_byrssi(struct net_device *dev); 166 - static void _rtl92e_dm_ctrl_initgain_byrssi_driver(struct net_device *dev); 167 166 static void _rtl92e_dm_initial_gain(struct net_device *dev); 168 167 static void _rtl92e_dm_pd_th(struct net_device *dev); 169 168 static void _rtl92e_dm_cs_ratio(struct net_device *dev); ··· 928 929 dm_digtable.rx_gain_range_min = DM_DIG_MIN; 929 930 } 930 931 931 - static void _rtl92e_dm_ctrl_initgain_byrssi(struct net_device *dev) 932 - { 933 - _rtl92e_dm_ctrl_initgain_byrssi_driver(dev); 934 - } 935 - 936 932 /*----------------------------------------------------------------------------- 937 933 * Function: dm_CtrlInitGainBeforeConnectByRssiAndFalseAlarm() 938 934 * ··· 946 952 * 947 953 ******************************************************************************/ 948 954 949 - static void _rtl92e_dm_ctrl_initgain_byrssi_driver(struct net_device *dev) 955 + static void _rtl92e_dm_ctrl_initgain_byrssi(struct net_device *dev) 950 956 { 951 957 struct r8192_priv *priv = rtllib_priv(dev); 952 958 u8 i;
+18 -18
drivers/staging/rtl8192e/rtl819x_HT.h
··· 24 24 }; 25 25 26 26 struct ht_capab_ele { 27 - u8 AdvCoding:1; 28 - u8 ChlWidth:1; 29 - u8 MimoPwrSave:2; 30 - u8 GreenField:1; 31 - u8 ShortGI20Mhz:1; 32 - u8 ShortGI40Mhz:1; 33 - u8 TxSTBC:1; 34 - u8 RxSTBC:2; 35 - u8 DelayBA:1; 36 - u8 MaxAMSDUSize:1; 37 - u8 DssCCk:1; 27 + u8 adv_coding:1; 28 + u8 chl_width:1; 29 + u8 mimo_pwr_save:2; 30 + u8 green_field:1; 31 + u8 short_gi_20mhz:1; 32 + u8 short_gi_40mhz:1; 33 + u8 tx_stbc:1; 34 + u8 rx_stbc:2; 35 + u8 delay_ba:1; 36 + u8 max_amsdu_size:1; 37 + u8 dss_cck:1; 38 38 u8 PSMP:1; 39 39 u8 Rsvd1:1; 40 - u8 LSigTxopProtect:1; 40 + u8 lsig_txop_protect:1; 41 41 42 - u8 MaxRxAMPDUFactor:2; 43 - u8 MPDUDensity:3; 42 + u8 max_rx_ampdu_factor:2; 43 + u8 mpdu_density:3; 44 44 u8 Rsvd2:3; 45 45 46 46 u8 MCS[16]; 47 47 48 - u16 ExtHTCapInfo; 48 + u16 ext_ht_cap_info; 49 49 50 50 u8 TxBFCap[4]; 51 51 ··· 62 62 u8 PSMPAccessOnly:1; 63 63 u8 SrvIntGranularity:3; 64 64 65 - u8 OptMode:2; 65 + u8 opt_mode:2; 66 66 u8 NonGFDevPresent:1; 67 67 u8 Revd1:5; 68 68 u8 Revd2:8; ··· 104 104 u8 ampdu_enable; 105 105 u8 current_ampdu_enable; 106 106 u8 ampdu_factor; 107 - u8 CurrentAMPDUFactor; 107 + u8 current_ampdu_factor; 108 108 u8 current_mpdu_density; 109 109 u8 forced_ampdu_factor; 110 110 u8 forced_mpdu_density; 111 111 u8 current_op_mode; 112 - enum ht_extchnl_offset CurSTAExtChnlOffset; 112 + enum ht_extchnl_offset cur_sta_ext_chnl_offset; 113 113 u8 cur_tx_bw40mhz; 114 114 u8 sw_bw_in_progress; 115 115 u8 current_rt2rt_aggregation;
+52 -52
drivers/staging/rtl8192e/rtl819x_HTProc.c
··· 235 235 236 236 if (!pos_ht_cap || !ht) { 237 237 netdev_warn(ieee->dev, 238 - "%s(): posHTCap and ht_info are null\n", __func__); 238 + "%s(): pos_ht_cap and ht_info are null\n", __func__); 239 239 return; 240 240 } 241 241 memset(pos_ht_cap, 0, *len); ··· 251 251 *len = 26 + 2; 252 252 } 253 253 254 - cap_ele->AdvCoding = 0; 254 + cap_ele->adv_coding = 0; 255 255 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) 256 - cap_ele->ChlWidth = 0; 256 + cap_ele->chl_width = 0; 257 257 else 258 - cap_ele->ChlWidth = 1; 258 + cap_ele->chl_width = 1; 259 259 260 - cap_ele->MimoPwrSave = 3; 261 - cap_ele->GreenField = 0; 262 - cap_ele->ShortGI20Mhz = 1; 263 - cap_ele->ShortGI40Mhz = 1; 260 + cap_ele->mimo_pwr_save = 3; 261 + cap_ele->green_field = 0; 262 + cap_ele->short_gi_20mhz = 1; 263 + cap_ele->short_gi_40mhz = 1; 264 264 265 - cap_ele->TxSTBC = 1; 266 - cap_ele->RxSTBC = 0; 267 - cap_ele->DelayBA = 0; 268 - cap_ele->MaxAMSDUSize = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0; 269 - cap_ele->DssCCk = 1; 265 + cap_ele->tx_stbc = 1; 266 + cap_ele->rx_stbc = 0; 267 + cap_ele->delay_ba = 0; 268 + cap_ele->max_amsdu_size = (MAX_RECEIVE_BUFFER_SIZE >= 7935) ? 1 : 0; 269 + cap_ele->dss_cck = 1; 270 270 cap_ele->PSMP = 0; 271 - cap_ele->LSigTxopProtect = 0; 271 + cap_ele->lsig_txop_protect = 0; 272 272 273 273 netdev_dbg(ieee->dev, 274 - "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", 275 - cap_ele->ChlWidth, cap_ele->MaxAMSDUSize, cap_ele->DssCCk); 274 + "TX HT cap/info ele BW=%d max_amsdu_size:%d dss_cck:%d\n", 275 + cap_ele->chl_width, cap_ele->max_amsdu_size, cap_ele->dss_cck); 276 276 277 277 if (is_encrypt) { 278 - cap_ele->MPDUDensity = 7; 279 - cap_ele->MaxRxAMPDUFactor = 2; 278 + cap_ele->mpdu_density = 7; 279 + cap_ele->max_rx_ampdu_factor = 2; 280 280 } else { 281 - cap_ele->MaxRxAMPDUFactor = 3; 282 - cap_ele->MPDUDensity = 0; 281 + cap_ele->max_rx_ampdu_factor = 3; 282 + cap_ele->mpdu_density = 0; 283 283 } 284 284 285 285 memcpy(cap_ele->MCS, ieee->reg_dot11ht_oper_rate_set, 16); 286 - memset(&cap_ele->ExtHTCapInfo, 0, 2); 286 + memset(&cap_ele->ext_ht_cap_info, 0, 2); 287 287 memset(cap_ele->TxBFCap, 0, 4); 288 288 289 289 cap_ele->ASCap = 0; ··· 299 299 cap_ele->MCS[1] &= 0x00; 300 300 301 301 if (ht->iot_action & HT_IOT_ACT_DISABLE_RX_40MHZ_SHORT_GI) 302 - cap_ele->ShortGI40Mhz = 0; 302 + cap_ele->short_gi_40mhz = 0; 303 303 304 304 if (ieee->get_half_nmode_support_by_aps_handler(ieee->dev)) { 305 - cap_ele->ChlWidth = 0; 305 + cap_ele->chl_width = 0; 306 306 cap_ele->MCS[1] = 0; 307 307 } 308 308 } ··· 452 452 print_hex_dump_bytes("%s: ", __func__, DUMP_PREFIX_NONE, 453 453 pPeerHTCap, sizeof(struct ht_capab_ele)); 454 454 #endif 455 - ht_set_connect_bw_mode(ieee, (enum ht_channel_width)(pPeerHTCap->ChlWidth), 455 + ht_set_connect_bw_mode(ieee, (enum ht_channel_width)(pPeerHTCap->chl_width), 456 456 (enum ht_extchnl_offset)(pPeerHTInfo->ExtChlOffset)); 457 457 ht_info->cur_tx_bw40mhz = ((pPeerHTInfo->RecommemdedTxWidth == 1) ? 458 458 true : false); 459 459 460 - ht_info->cur_short_gi_20mhz = ((pPeerHTCap->ShortGI20Mhz == 1) ? true : false); 461 - ht_info->cur_short_gi_40mhz = ((pPeerHTCap->ShortGI40Mhz == 1) ? true : false); 460 + ht_info->cur_short_gi_20mhz = ((pPeerHTCap->short_gi_20mhz == 1) ? true : false); 461 + ht_info->cur_short_gi_40mhz = ((pPeerHTCap->short_gi_40mhz == 1) ? true : false); 462 462 463 463 ht_info->current_ampdu_enable = ht_info->ampdu_enable; 464 464 if (ieee->rtllib_ap_sec_type && ··· 470 470 471 471 if (ieee->current_network.bssht.bd_rt2rt_aggregation) { 472 472 if (ieee->pairwise_key_type != KEY_TYPE_NA) 473 - ht_info->CurrentAMPDUFactor = 474 - pPeerHTCap->MaxRxAMPDUFactor; 473 + ht_info->current_ampdu_factor = 474 + pPeerHTCap->max_rx_ampdu_factor; 475 475 else 476 - ht_info->CurrentAMPDUFactor = HT_AGG_SIZE_64K; 476 + ht_info->current_ampdu_factor = HT_AGG_SIZE_64K; 477 477 } else { 478 - ht_info->CurrentAMPDUFactor = min_t(u32, pPeerHTCap->MaxRxAMPDUFactor, 479 - HT_AGG_SIZE_32K); 478 + ht_info->current_ampdu_factor = min_t(u32, pPeerHTCap->max_rx_ampdu_factor, 479 + HT_AGG_SIZE_32K); 480 480 } 481 481 482 - ht_info->current_mpdu_density = pPeerHTCap->MPDUDensity; 482 + ht_info->current_mpdu_density = pPeerHTCap->mpdu_density; 483 483 if (ht_info->iot_action & HT_IOT_ACT_TX_USE_AMSDU_8K) 484 484 ht_info->current_ampdu_enable = false; 485 485 ··· 498 498 pMcsFilter); 499 499 ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate; 500 500 501 - ht_info->current_op_mode = pPeerHTInfo->OptMode; 501 + ht_info->current_op_mode = pPeerHTInfo->opt_mode; 502 502 } 503 503 504 504 void ht_initialize_ht_info(struct rtllib_device *ieee) ··· 514 514 ht_info->cur_short_gi_40mhz = false; 515 515 516 516 ht_info->current_mpdu_density = 0; 517 - ht_info->CurrentAMPDUFactor = ht_info->ampdu_factor; 517 + ht_info->current_ampdu_factor = ht_info->ampdu_factor; 518 518 519 519 memset((void *)(&ht_info->self_ht_cap), 0, 520 520 sizeof(ht_info->self_ht_cap)); ··· 543 543 } 544 544 } 545 545 546 - void ht_initialize_bss_desc(struct bss_ht *pBssHT) 546 + void ht_initialize_bss_desc(struct bss_ht *bss_ht) 547 547 { 548 - pBssHT->bd_support_ht = false; 549 - memset(pBssHT->bd_ht_cap_buf, 0, sizeof(pBssHT->bd_ht_cap_buf)); 550 - pBssHT->bd_ht_cap_len = 0; 551 - memset(pBssHT->bd_ht_info_buf, 0, sizeof(pBssHT->bd_ht_info_buf)); 552 - pBssHT->bd_ht_info_len = 0; 548 + bss_ht->bd_support_ht = false; 549 + memset(bss_ht->bd_ht_cap_buf, 0, sizeof(bss_ht->bd_ht_cap_buf)); 550 + bss_ht->bd_ht_cap_len = 0; 551 + memset(bss_ht->bd_ht_info_buf, 0, sizeof(bss_ht->bd_ht_info_buf)); 552 + bss_ht->bd_ht_info_len = 0; 553 553 554 - pBssHT->bd_ht_spec_ver = HT_SPEC_VER_IEEE; 554 + bss_ht->bd_ht_spec_ver = HT_SPEC_VER_IEEE; 555 555 556 - pBssHT->bd_rt2rt_aggregation = false; 557 - pBssHT->bd_rt2rt_long_slot_time = false; 558 - pBssHT->rt2rt_ht_mode = (enum rt_ht_capability)0; 556 + bss_ht->bd_rt2rt_aggregation = false; 557 + bss_ht->bd_rt2rt_long_slot_time = false; 558 + bss_ht->rt2rt_ht_mode = (enum rt_ht_capability)0; 559 559 } 560 560 561 561 void ht_reset_self_and_save_peer_setting(struct rtllib_device *ieee, ··· 617 617 618 618 if (ht_info->current_ht_support) { 619 619 if (pNetwork->bssht.bd_ht_info_len != 0) 620 - ht_info->current_op_mode = pPeerHTInfo->OptMode; 620 + ht_info->current_op_mode = pPeerHTInfo->opt_mode; 621 621 } 622 622 } 623 623 EXPORT_SYMBOL(HT_update_self_and_peer_setting); ··· 625 625 u8 ht_c_check(struct rtllib_device *ieee, u8 *pFrame) 626 626 { 627 627 if (ieee->ht_info->current_ht_support) { 628 - if ((IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1) { 628 + if ((IsQoSDataFrame(pFrame) && frame_order(pFrame)) == 1) { 629 629 netdev_dbg(ieee->dev, "HT CONTROL FILED EXIST!!\n"); 630 630 return true; 631 631 } ··· 638 638 struct rt_hi_throughput *ht_info = ieee->ht_info; 639 639 640 640 if (ht_info->cur_bw_40mhz) { 641 - if (ht_info->CurSTAExtChnlOffset == HT_EXTCHNL_OFFSET_UPPER) 641 + if (ht_info->cur_sta_ext_chnl_offset == HT_EXTCHNL_OFFSET_UPPER) 642 642 ieee->set_chan(ieee->dev, 643 643 ieee->current_network.channel + 2); 644 - else if (ht_info->CurSTAExtChnlOffset == 644 + else if (ht_info->cur_sta_ext_chnl_offset == 645 645 HT_EXTCHNL_OFFSET_LOWER) 646 646 ieee->set_chan(ieee->dev, 647 647 ieee->current_network.channel - 2); ··· 650 650 ieee->current_network.channel); 651 651 652 652 ieee->set_bw_mode_handler(ieee->dev, HT_CHANNEL_WIDTH_20_40, 653 - ht_info->CurSTAExtChnlOffset); 653 + ht_info->cur_sta_ext_chnl_offset); 654 654 } else { 655 655 ieee->set_chan(ieee->dev, ieee->current_network.channel); 656 656 ieee->set_bw_mode_handler(ieee->dev, HT_CHANNEL_WIDTH_20, ··· 680 680 if (Offset == HT_EXTCHNL_OFFSET_UPPER || 681 681 Offset == HT_EXTCHNL_OFFSET_LOWER) { 682 682 ht_info->cur_bw_40mhz = true; 683 - ht_info->CurSTAExtChnlOffset = Offset; 683 + ht_info->cur_sta_ext_chnl_offset = Offset; 684 684 } else { 685 685 ht_info->cur_bw_40mhz = false; 686 - ht_info->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; 686 + ht_info->cur_sta_ext_chnl_offset = HT_EXTCHNL_OFFSET_NO_EXT; 687 687 } 688 688 } else { 689 689 ht_info->cur_bw_40mhz = false; 690 - ht_info->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT; 690 + ht_info->cur_sta_ext_chnl_offset = HT_EXTCHNL_OFFSET_NO_EXT; 691 691 } 692 692 693 693 netdev_dbg(ieee->dev, "%s():ht_info->bCurBW40MHz:%x\n", __func__,
+10 -10
drivers/staging/rtl8192e/rtllib.h
··· 121 121 122 122 u8 bRTSBW:1; 123 123 u8 bPacketBW:1; 124 - u8 bRTSUseShortPreamble:1; 124 + u8 rts_use_short_preamble:1; 125 125 u8 bRTSUseShortGI:1; 126 126 u8 multicast:1; 127 127 u8 bBroadcast:1; ··· 299 299 RT_OP_MODE_NO_LINK, 300 300 }; 301 301 302 - #define aSifsTime \ 302 + #define asifs_time \ 303 303 ((priv->rtllib->current_network.mode == WIRELESS_MODE_N_24G) ? 16 : 10) 304 304 305 305 #define MGMT_QUEUE_NUM 5 ··· 343 343 #define IsQoSDataFrame(pframe) \ 344 344 ((*(u16 *)pframe&(IEEE80211_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) == \ 345 345 (IEEE80211_STYPE_QOS_DATA|RTLLIB_FTYPE_DATA)) 346 - #define Frame_Order(pframe) (*(u16 *)pframe&IEEE80211_FCTL_ORDER) 346 + #define frame_order(pframe) (*(u16 *)pframe&IEEE80211_FCTL_ORDER) 347 347 #define SN_LESS(a, b) (((a-b)&0x800) != 0) 348 348 #define SN_EQUAL(a, b) (a == b) 349 349 #define MAX_DEV_ADDR_SIZE 8 ··· 482 482 u16 bCRC:1; 483 483 u16 bICV:1; 484 484 u16 Decrypted:1; 485 - u32 TimeStampLow; 486 - u32 TimeStampHigh; 485 + u32 time_stamp_low; 486 + u32 time_stamp_high; 487 487 488 488 u8 RxDrvInfoSize; 489 489 u8 RxBufShift; ··· 1051 1051 struct rt_pwr_save_ctrl { 1052 1052 bool bSwRfProcessing; 1053 1053 enum rt_rf_power_state eInactivePowerState; 1054 - enum ips_callback_function ReturnPoint; 1054 + enum ips_callback_function return_point; 1055 1055 1056 1056 bool bLeisurePs; 1057 1057 u8 lps_idle_count; ··· 1477 1477 void (*set_hw_reg_handler)(struct net_device *dev, u8 variable, u8 *val); 1478 1478 1479 1479 void (*allow_all_dest_addr_handler)(struct net_device *dev, 1480 - bool bAllowAllDA, 1481 - bool WriteIntoReg); 1480 + bool allow_all_da, 1481 + bool write_into_reg); 1482 1482 1483 1483 void (*rtllib_ips_leave_wq)(struct net_device *dev); 1484 1484 void (*rtllib_ips_leave)(struct net_device *dev); ··· 1736 1736 enum ht_extchnl_offset Offset); 1737 1737 void ht_update_default_setting(struct rtllib_device *ieee); 1738 1738 void ht_construct_capability_element(struct rtllib_device *ieee, 1739 - u8 *posHTCap, u8 *len, 1739 + u8 *pos_ht_cap, u8 *len, 1740 1740 u8 isEncrypt, bool bAssoc); 1741 1741 void ht_construct_rt2rt_agg_element(struct rtllib_device *ieee, 1742 1742 u8 *posRT2RTAgg, u8 *len); 1743 1743 void ht_on_assoc_rsp(struct rtllib_device *ieee); 1744 1744 void ht_initialize_ht_info(struct rtllib_device *ieee); 1745 - void ht_initialize_bss_desc(struct bss_ht *pBssHT); 1745 + void ht_initialize_bss_desc(struct bss_ht *bss_ht); 1746 1746 void ht_reset_self_and_save_peer_setting(struct rtllib_device *ieee, 1747 1747 struct rtllib_network *pNetwork); 1748 1748 void HT_update_self_and_peer_setting(struct rtllib_device *ieee,
+1 -1
drivers/staging/rtl8192e/rtllib_rx.c
··· 1877 1877 1878 1878 ht->bd_bandwidth = (enum ht_channel_width) 1879 1879 (((struct ht_capab_ele *) 1880 - (ht->bd_ht_cap_buf))->ChlWidth); 1880 + (ht->bd_ht_cap_buf))->chl_width); 1881 1881 } else { 1882 1882 ht->bd_support_ht = false; 1883 1883 ht->bd_ht_1r = false;
+1 -1
drivers/staging/rtl8192e/rtllib_softmac_wx.c
··· 319 319 if (ieee->ht_info->current_ht_support && ieee->ht_info->enable_ht && 320 320 ieee->ht_info->cur_bw_40mhz) { 321 321 b40M = 1; 322 - chan_offset = ieee->ht_info->CurSTAExtChnlOffset; 322 + chan_offset = ieee->ht_info->cur_sta_ext_chnl_offset; 323 323 bandwidth = (enum ht_channel_width)ieee->ht_info->cur_bw_40mhz; 324 324 ieee->set_bw_mode_handler(ieee->dev, HT_CHANNEL_WIDTH_20, 325 325 HT_EXTCHNL_OFFSET_NO_EXT);
+1 -1
drivers/staging/rtl8192e/rtllib_tx.c
··· 313 313 } 314 314 if (ieee->iw_mode == IW_MODE_INFRA) { 315 315 tcb_desc->ampdu_enable = true; 316 - tcb_desc->ampdu_factor = ht_info->CurrentAMPDUFactor; 316 + tcb_desc->ampdu_factor = ht_info->current_ampdu_factor; 317 317 tcb_desc->ampdu_density = ht_info->current_mpdu_density; 318 318 } 319 319 }
+4 -4
drivers/staging/rtl8192e/rtllib_wx.c
··· 129 129 else 130 130 ht_cap = (struct ht_capab_ele *) 131 131 &network->bssht.bd_ht_cap_buf[0]; 132 - is40M = (ht_cap->ChlWidth) ? 1 : 0; 133 - isShortGI = (ht_cap->ChlWidth) ? 134 - ((ht_cap->ShortGI40Mhz) ? 1 : 0) : 135 - ((ht_cap->ShortGI20Mhz) ? 1 : 0); 132 + is40M = (ht_cap->chl_width) ? 1 : 0; 133 + isShortGI = (ht_cap->chl_width) ? 134 + ((ht_cap->short_gi_40mhz) ? 1 : 0) : 135 + ((ht_cap->short_gi_20mhz) ? 1 : 0); 136 136 137 137 max_mcs = ht_get_highest_mcs_rate(ieee, ht_cap->MCS, 138 138 MCS_FILTER_ALL);
+9 -9
drivers/staging/rtl8712/mlme_linux.c
··· 84 84 netif_carrier_on(adapter->pnetdev); 85 85 } 86 86 87 - static struct RT_PMKID_LIST backupPMKIDList[NUM_PMKID_CACHE]; 87 + static struct RT_PMKID_LIST backup_PMKID_list[NUM_PMKID_CACHE]; 88 88 void r8712_os_indicate_disconnect(struct _adapter *adapter) 89 89 { 90 - u8 backupPMKIDIndex = 0; 91 - u8 backupTKIPCountermeasure = 0x00; 90 + u8 backup_PMKID_index = 0; 91 + u8 backup_TKIP_countermeasure = 0x00; 92 92 93 93 r8712_indicate_wx_disassoc_event(adapter); 94 94 netif_carrier_off(adapter->pnetdev); ··· 99 99 * disconnect with AP for 60 seconds. 100 100 */ 101 101 102 - memcpy(&backupPMKIDList[0], 102 + memcpy(&backup_PMKID_list[0], 103 103 &adapter->securitypriv.PMKIDList[0], 104 104 sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE); 105 - backupPMKIDIndex = adapter->securitypriv.PMKIDIndex; 106 - backupTKIPCountermeasure = 105 + backup_PMKID_index = adapter->securitypriv.PMKIDIndex; 106 + backup_TKIP_countermeasure = 107 107 adapter->securitypriv.btkip_countermeasure; 108 108 memset((unsigned char *)&adapter->securitypriv, 0, 109 109 sizeof(struct security_priv)); ··· 113 113 * for the following connection. 114 114 */ 115 115 memcpy(&adapter->securitypriv.PMKIDList[0], 116 - &backupPMKIDList[0], 116 + &backup_PMKID_list[0], 117 117 sizeof(struct RT_PMKID_LIST) * NUM_PMKID_CACHE); 118 - adapter->securitypriv.PMKIDIndex = backupPMKIDIndex; 118 + adapter->securitypriv.PMKIDIndex = backup_PMKID_index; 119 119 adapter->securitypriv.btkip_countermeasure = 120 - backupTKIPCountermeasure; 120 + backup_TKIP_countermeasure; 121 121 } else { /*reset values in securitypriv*/ 122 122 struct security_priv *sec_priv = &adapter->securitypriv; 123 123
+2 -1
drivers/staging/rtl8712/os_intfs.c
··· 221 221 222 222 static u32 start_drv_threads(struct _adapter *padapter) 223 223 { 224 - padapter->cmd_thread = kthread_run(r8712_cmd_thread, padapter, "%s", padapter->pnetdev->name); 224 + padapter->cmd_thread = kthread_run(r8712_cmd_thread, padapter, "%s", 225 + padapter->pnetdev->name); 225 226 if (IS_ERR(padapter->cmd_thread)) 226 227 return _FAIL; 227 228 return _SUCCESS;
+1 -1
drivers/staging/rtl8712/rtl8712_led.c
··· 107 107 */ 108 108 static void SwLedOn(struct _adapter *padapter, struct LED_871x *pLed) 109 109 { 110 - u8 LedCfg; 110 + u8 LedCfg; 111 111 112 112 if (padapter->surprise_removed || padapter->driver_stopped) 113 113 return;
+3 -3
drivers/staging/rtl8712/rtl8712_recv.c
··· 861 861 static void process_link_qual(struct _adapter *padapter, 862 862 union recv_frame *prframe) 863 863 { 864 - u32 last_evm = 0, tmpVal; 864 + u32 last_evm = 0, avg_val; 865 865 struct rx_pkt_attrib *pattrib; 866 866 struct smooth_rssi_data *sqd = &padapter->recvpriv.signal_qual_data; 867 867 ··· 883 883 sqd->index = 0; 884 884 885 885 /* <1> Showed on UI for user, in percentage. */ 886 - tmpVal = sqd->total_val / sqd->total_num; 887 - padapter->recvpriv.signal = (u8)tmpVal; 886 + avg_val = sqd->total_val / sqd->total_num; 887 + padapter->recvpriv.signal = (u8)avg_val; 888 888 } 889 889 } 890 890
+1 -1
drivers/staging/rtl8712/rtl8712_recv.h
··· 82 82 83 83 union recvstat { 84 84 struct recv_stat recv_stat; 85 - unsigned int value[RXDESC_SIZE>>2]; 85 + unsigned int value[RXDESC_SIZE >> 2]; 86 86 }; 87 87 88 88 struct recv_buf {
+5 -87
drivers/staging/rtl8723bs/core/rtw_mlme.c
··· 22 22 23 23 pmlmepriv->pscanned = NULL; 24 24 pmlmepriv->fw_state = WIFI_STATION_STATE; /* Must sync with rtw_wdev_alloc() */ 25 - /* wdev->iftype = NL80211_IFTYPE_STATION */ 26 25 pmlmepriv->cur_network.network.infrastructure_mode = Ndis802_11AutoUnknown; 27 26 pmlmepriv->scan_mode = SCAN_ACTIVE;/* 1: active, 0: passive. Maybe someday we should rename this varable to "active_mode" (Jeff) */ 28 27 ··· 108 109 } 109 110 } 110 111 111 - /* 112 - struct wlan_network *_rtw_dequeue_network(struct __queue *queue) 113 - { 114 - _irqL irqL; 115 - 116 - struct wlan_network *pnetwork; 117 - 118 - spin_lock_bh(&queue->lock); 119 - 120 - if (list_empty(&queue->queue)) 121 - 122 - pnetwork = NULL; 123 - 124 - else 125 - { 126 - pnetwork = container_of(get_next(&queue->queue), struct wlan_network, list); 127 - 128 - list_del_init(&(pnetwork->list)); 129 - } 130 - 131 - spin_unlock_bh(&queue->lock); 132 - 133 - return pnetwork; 134 - } 135 - */ 136 - 137 112 struct wlan_network *rtw_alloc_network(struct mlme_priv *pmlmepriv) 138 113 { 139 114 struct wlan_network *pnetwork; ··· 180 207 if (pnetwork->fixed) 181 208 return; 182 209 183 - /* spin_lock_irqsave(&free_queue->lock, irqL); */ 184 - 185 210 list_del_init(&(pnetwork->list)); 186 211 187 212 list_add_tail(&(pnetwork->list), get_list_head(free_queue)); 188 - 189 - /* spin_unlock_irqrestore(&free_queue->lock, irqL); */ 190 213 } 191 214 192 215 /* ··· 200 231 goto exit; 201 232 } 202 233 203 - /* spin_lock_bh(&scanned_queue->lock); */ 204 - 205 234 phead = get_list_head(scanned_queue); 206 235 list_for_each(plist, phead) { 207 236 pnetwork = list_entry(plist, struct wlan_network, list); ··· 210 243 211 244 if (plist == phead) 212 245 pnetwork = NULL; 213 - 214 - /* spin_unlock_bh(&scanned_queue->lock); */ 215 246 216 247 exit: 217 248 return pnetwork; ··· 284 319 { 285 320 _rtw_free_mlme_priv(pmlmepriv); 286 321 } 287 - 288 - /* 289 - static struct wlan_network *rtw_dequeue_network(struct __queue *queue) 290 - { 291 - struct wlan_network *pnetwork; 292 - 293 - pnetwork = _rtw_dequeue_network(queue); 294 - return pnetwork; 295 - } 296 - */ 297 322 298 323 void rtw_free_network_nolock(struct adapter *padapter, struct wlan_network *pnetwork); 299 324 void rtw_free_network_nolock(struct adapter *padapter, struct wlan_network *pnetwork) ··· 449 494 &(pmlmepriv->cur_network.network)); 450 495 451 496 if ((check_fwstate(pmlmepriv, _FW_LINKED) == true) && (is_same_network(&(pmlmepriv->cur_network.network), pnetwork, 0))) { 452 - /* if (pmlmepriv->cur_network.network.ie_length<= pnetwork->ie_length) */ 453 - { 454 - update_network(&(pmlmepriv->cur_network.network), pnetwork, adapter, true); 455 - rtw_update_protection(adapter, (pmlmepriv->cur_network.network.ies) + sizeof(struct ndis_802_11_fix_ie), 456 - pmlmepriv->cur_network.network.ie_length); 457 - } 497 + update_network(&(pmlmepriv->cur_network.network), pnetwork, adapter, true); 498 + rtw_update_protection(adapter, (pmlmepriv->cur_network.network.ies) + sizeof(struct ndis_802_11_fix_ie), 499 + pmlmepriv->cur_network.network.ie_length); 458 500 } 459 501 } 460 502 ··· 492 540 493 541 /* If we didn't find a match, then get a new network slot to initialize 494 542 * with this beacon's information */ 495 - /* if (phead == plist) { */ 496 543 if (!target_find) { 497 544 if (list_empty(&pmlmepriv->free_bss_pool.queue)) { 498 545 /* If there are no more slots, expire the oldest */ ··· 564 613 void rtw_add_network(struct adapter *adapter, struct wlan_bssid_ex *pnetwork); 565 614 void rtw_add_network(struct adapter *adapter, struct wlan_bssid_ex *pnetwork) 566 615 { 567 - /* struct __queue *queue = &(pmlmepriv->scanned_queue); */ 568 - 569 - /* spin_lock_bh(&queue->lock); */ 570 - 571 616 update_current_network(adapter, pnetwork); 572 - 573 617 rtw_update_scanned_network(adapter, pnetwork); 574 - 575 - /* spin_unlock_bh(&queue->lock); */ 576 618 } 577 619 578 620 /* select the desired network based on the capability of the (i)bss. */ ··· 581 637 struct mlme_priv *pmlmepriv = &adapter->mlmepriv; 582 638 u32 desired_encmode; 583 639 u32 privacy; 584 - 585 - /* u8 wps_ie[512]; */ 586 640 uint wps_ielen; 587 - 588 641 int bselected = true; 589 642 590 643 desired_encmode = psecuritypriv->ndisencryptstatus; ··· 993 1052 memset((u8 *)&psta->dot11rxpn, 0, sizeof(union pn48)); 994 1053 } 995 1054 996 - /* Commented by Albert 2012/07/21 */ 997 - /* When doing the WPS, the wps_ie_len won't equal to 0 */ 998 - /* And the Wi-Fi driver shouldn't allow the data packet to be transmitted. */ 1055 + /* When doing the WPS, the wps_ie_len won't equal to 0 */ 1056 + /* And the Wi-Fi driver shouldn't allow the data packet to be transmitted. */ 999 1057 if (padapter->securitypriv.wps_ie_len != 0) { 1000 1058 psta->ieee8021x_blocked = true; 1001 1059 padapter->securitypriv.wps_ie_len = 0; ··· 1004 1064 /* if A-MPDU Rx is enabled, resetting rx_ordering_ctrl wstart_b(indicate_seq) to default value = 0xffff */ 1005 1065 /* todo: check if AP can send A-MPDU packets */ 1006 1066 for (i = 0; i < 16 ; i++) { 1007 - /* preorder_ctrl = &precvpriv->recvreorder_ctrl[i]; */ 1008 1067 preorder_ctrl = &psta->recvreorder_ctrl[i]; 1009 1068 preorder_ctrl->enable = false; 1010 1069 preorder_ctrl->indicate_seq = 0xffff; ··· 1014 1075 bmc_sta = rtw_get_bcmc_stainfo(padapter); 1015 1076 if (bmc_sta) { 1016 1077 for (i = 0; i < 16 ; i++) { 1017 - /* preorder_ctrl = &precvpriv->recvreorder_ctrl[i]; */ 1018 1078 preorder_ctrl = &bmc_sta->recvreorder_ctrl[i]; 1019 1079 preorder_ctrl->enable = false; 1020 1080 preorder_ctrl->indicate_seq = 0xffff; ··· 1177 1239 rtw_reset_securitypriv(adapter); 1178 1240 _set_timer(&pmlmepriv->assoc_timer, 1); 1179 1241 1180 - /* rtw_free_assoc_resources(adapter, 1); */ 1181 - 1182 1242 if ((check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) == true) 1183 1243 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); 1184 1244 ··· 1198 1262 #endif 1199 1263 1200 1264 _set_timer(&pmlmepriv->assoc_timer, 1); 1201 - /* rtw_free_assoc_resources(adapter, 1); */ 1202 1265 _clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING); 1203 1266 1204 1267 #ifdef REJOIN ··· 1292 1357 /* to do : init sta_info variable */ 1293 1358 psta->qos_option = 0; 1294 1359 psta->mac_id = (uint)pstassoc->cam_id; 1295 - /* psta->aid = (uint)pstassoc->cam_id; */ 1296 1360 1297 1361 /* for ad-hoc mode */ 1298 1362 rtw_hal_set_odm_var(adapter, HAL_ODM_STA_INFO, psta, true); ··· 1406 1472 1407 1473 if (adapter->stapriv.asoc_sta_count == 1) {/* a sta + bc/mc_stainfo (not Ibss_stainfo) */ 1408 1474 u8 ret = _SUCCESS; 1409 - /* rtw_indicate_disconnect(adapter);removed@20091105 */ 1410 1475 spin_lock_bh(&(pmlmepriv->scanned_queue.lock)); 1411 1476 /* free old ibss network */ 1412 - /* pwlan = rtw_find_network(&pmlmepriv->scanned_queue, pstadel->macaddr); */ 1413 1477 pwlan = rtw_find_network(&pmlmepriv->scanned_queue, tgt_network->network.mac_address); 1414 1478 if (pwlan) { 1415 1479 pwlan->fixed = false; ··· 2020 2088 } else if ((authmode == WLAN_EID_VENDOR_SPECIFIC) || (authmode == WLAN_EID_RSN)) { 2021 2089 /* copy RSN or SSN */ 2022 2090 memcpy(&out_ie[ielength], &psecuritypriv->supplicant_ie[0], psecuritypriv->supplicant_ie[1]+2); 2023 - /* debug for CONFIG_IEEE80211W 2024 - { 2025 - int jj; 2026 - printk("supplicant_ie_length =%d &&&&&&&&&&&&&&&&&&&\n", psecuritypriv->supplicant_ie[1]+2); 2027 - for (jj = 0; jj < psecuritypriv->supplicant_ie[1]+2; jj++) 2028 - printk(" %02x ", psecuritypriv->supplicant_ie[jj]); 2029 - printk("\n"); 2030 - }*/ 2031 2091 ielength += psecuritypriv->supplicant_ie[1]+2; 2032 2092 rtw_report_sec_ie(adapter, authmode, psecuritypriv->supplicant_ie); 2033 2093 } ··· 2056 2132 struct wlan_bssid_ex *pdev_network = &pregistrypriv->dev_network; 2057 2133 struct security_priv *psecuritypriv = &adapter->securitypriv; 2058 2134 struct wlan_network *cur_network = &adapter->mlmepriv.cur_network; 2059 - /* struct xmit_priv *pxmitpriv = &adapter->xmitpriv; */ 2060 2135 2061 2136 pdev_network->privacy = (psecuritypriv->dot11PrivacyAlgrthm > 0 ? 1 : 0) ; /* adhoc no 802.1x */ 2062 2137 ··· 2304 2381 rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, 2305 2382 &max_rx_ampdu_factor); 2306 2383 2307 - /* rtw_hal_get_def_var(padapter, HW_VAR_MAX_RX_AMPDU_FACTOR, &max_rx_ampdu_factor); */ 2308 2384 ht_capie.ampdu_params_info = (max_rx_ampdu_factor&0x03); 2309 2385 2310 2386 if (padapter->securitypriv.dot11PrivacyAlgrthm == _AES_) ··· 2333 2411 { 2334 2412 u8 *p, max_ampdu_sz; 2335 2413 int len; 2336 - /* struct sta_info *bmc_sta, *psta; */ 2337 2414 struct ieee80211_ht_cap *pht_capie; 2338 - /* struct recv_reorder_ctrl *preorder_ctrl; */ 2339 2415 struct mlme_priv *pmlmepriv = &padapter->mlmepriv; 2340 2416 struct ht_priv *phtpriv = &pmlmepriv->htpriv; 2341 - /* struct recv_priv *precvpriv = &padapter->recvpriv; */ 2342 2417 struct registry_priv *pregistrypriv = &padapter->registrypriv; 2343 - /* struct wlan_network *pcur_network = &(pmlmepriv->cur_network);; */ 2344 2418 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv; 2345 2419 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 2346 2420 u8 cbw40_enable = 0;
+2 -3
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
··· 884 884 goto addkey_end; 885 885 } 886 886 887 - strncpy((char *)param->u.crypt.alg, alg_name, IEEE_CRYPT_ALG_NAME_LEN); 887 + strscpy(param->u.crypt.alg, alg_name); 888 888 889 889 if (!mac_addr || is_broadcast_ether_addr(mac_addr)) 890 890 param->u.crypt.set_tx = 0; /* for wpa/wpa2 group key */ ··· 2143 2143 } 2144 2144 2145 2145 mon_ndev->type = ARPHRD_IEEE80211_RADIOTAP; 2146 - strncpy(mon_ndev->name, name, IFNAMSIZ); 2147 - mon_ndev->name[IFNAMSIZ - 1] = 0; 2146 + strscpy(mon_ndev->name, name); 2148 2147 mon_ndev->needs_free_netdev = true; 2149 2148 mon_ndev->priv_destructor = rtw_ndev_destructor; 2150 2149
+1 -1
drivers/staging/rtl8723bs/os_dep/os_intfs.c
··· 415 415 struct adapter *adapter = rtw_netdev_priv(dev); 416 416 417 417 netdev_dbg(dev, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter)); 418 - strncpy(adapter->old_ifname, dev->name, IFNAMSIZ); 418 + strscpy(adapter->old_ifname, dev->name); 419 419 420 420 return 0; 421 421 }
+5 -5
drivers/staging/rts5208/rtsx_scsi.c
··· 463 463 static int inquiry(struct scsi_cmnd *srb, struct rtsx_chip *chip) 464 464 { 465 465 unsigned int lun = SCSI_LUN(srb); 466 - char *inquiry_default = (char *)"Generic-xD/SD/M.S. 1.00 "; 467 - char *inquiry_sdms = (char *)"Generic-SD/MemoryStick 1.00 "; 468 - char *inquiry_sd = (char *)"Generic-SD/MMC 1.00 "; 469 - char *inquiry_ms = (char *)"Generic-MemoryStick 1.00 "; 466 + char *inquiry_default = (char *)"Generic-xD/SD/M.S. 1.00"; 467 + char *inquiry_sdms = (char *)"Generic-SD/MemoryStick 1.00"; 468 + char *inquiry_sd = (char *)"Generic-SD/MMC 1.00"; 469 + char *inquiry_ms = (char *)"Generic-MemoryStick 1.00"; 470 470 char *inquiry_string; 471 471 unsigned char sendbytes; 472 472 unsigned char *buf; ··· 523 523 524 524 if (sendbytes > 8) { 525 525 memcpy(buf, inquiry_buf, 8); 526 - strncpy(buf + 8, inquiry_string, sendbytes - 8); 526 + memcpy(buf + 8, inquiry_string, min(sendbytes, 36) - 8); 527 527 if (pro_formatter_flag) { 528 528 /* Additional Length */ 529 529 buf[4] = 0x33;
+21 -15
drivers/staging/vc04_services/Kconfig
··· 16 16 depends on HAS_DMA 17 17 imply VCHIQ_CDEV 18 18 help 19 - Broadcom BCM2835 and similar SoCs have a VPU called VideoCore. This config 20 - enables the VCHIQ driver, which implements a messaging interface between 21 - the kernel and the firmware running on VideoCore. Other drivers use this 22 - interface to communicate to the VPU. More specifically, the VCHIQ driver is 23 - used by audio/video and camera drivers as well as for implementing MMAL 24 - API, which is in turn used by several multimedia services on the BCM2835 25 - family of SoCs. 26 - Defaults to Y when the Broadcom Videocore services are included in 27 - the build, N otherwise. 19 + Broadcom BCM2835 and similar SoCs have a VPU called VideoCore. 20 + This config enables the VCHIQ driver, which implements a 21 + messaging interface between the kernel and the firmware running 22 + on VideoCore. Other drivers use this interface to communicate to 23 + the VPU. More specifically, the VCHIQ driver is used by 24 + audio/video and camera drivers as well as for implementing MMAL 25 + API, which is in turn used by several multimedia services on the 26 + BCM2835 family of SoCs. 27 + 28 + Defaults to Y when the Broadcom Videocore services are included 29 + in the build, N otherwise. 28 30 29 31 if BCM2835_VCHIQ 30 32 31 33 config VCHIQ_CDEV 32 34 bool "VCHIQ Character Driver" 33 35 help 34 - Enable the creation of VCHIQ character driver. The cdev exposes ioctls used 35 - by userspace libraries and testing tools to interact with VideoCore, via 36 - the VCHIQ core driver (Check BCM2835_VCHIQ for more info). 37 - This can be set to 'N' if the VideoCore communication is not needed by 38 - userspace but only by other kernel modules (like bcm2835-audio). If not 39 - sure, set this to 'Y'. 36 + Enable the creation of VCHIQ character driver. The cdev exposes 37 + ioctls used by userspace libraries and testing tools to interact 38 + with VideoCore, via the VCHIQ core driver (Check BCM2835_VCHIQ 39 + for more info). 40 + 41 + This can be set to 'N' if the VideoCore communication is not 42 + needed by userspace but only by other kernel modules 43 + (like bcm2835-audio). 44 + 45 + If not sure, set this to 'Y'. 40 46 41 47 endif 42 48
-1
drivers/staging/vc04_services/Makefile
··· 6 6 interface/vchiq_arm/vchiq_arm.o \ 7 7 interface/vchiq_arm/vchiq_bus.o \ 8 8 interface/vchiq_arm/vchiq_debugfs.o \ 9 - interface/vchiq_arm/vchiq_connected.o \ 10 9 11 10 ifdef CONFIG_VCHIQ_CDEV 12 11 vchiq-objs += interface/vchiq_arm/vchiq_dev.o
drivers/staging/vc04_services/bcm2835-audio/Kconfig
+4 -1
drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
··· 7 7 #include "bcm2835.h" 8 8 #include "vc_vchi_audioserv_defs.h" 9 9 10 + #include "../interface/vchiq_arm/vchiq_arm.h" 11 + 10 12 struct bcm2835_audio_instance { 11 13 struct device *dev; 12 14 unsigned int service_handle; ··· 177 175 178 176 int bcm2835_new_vchi_ctx(struct device *dev, struct bcm2835_vchi_ctx *vchi_ctx) 179 177 { 178 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(dev->parent); 180 179 int ret; 181 180 182 181 /* Initialize and create a VCHI connection */ 183 - ret = vchiq_initialise(&vchi_ctx->instance); 182 + ret = vchiq_initialise(&mgmt->state, &vchi_ctx->instance); 184 183 if (ret) { 185 184 dev_err(dev, "failed to initialise VCHI instance (ret=%d)\n", 186 185 ret);
+2 -2
drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
··· 1555 1555 u32 param_size; 1556 1556 struct vchiq_mmal_component *camera; 1557 1557 1558 - ret = vchiq_mmal_init(&dev->instance); 1558 + ret = vchiq_mmal_init(dev->v4l2_dev.dev, &dev->instance); 1559 1559 if (ret < 0) { 1560 1560 v4l2_err(&dev->v4l2_dev, "%s: vchiq mmal init failed %d\n", 1561 1561 __func__, ret); ··· 1854 1854 return ret; 1855 1855 } 1856 1856 1857 - ret = vchiq_mmal_init(&instance); 1857 + ret = vchiq_mmal_init(&device->dev, &instance); 1858 1858 if (ret < 0) 1859 1859 return ret; 1860 1860
+3 -1
drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h
··· 48 48 }; 49 49 50 50 struct vchiq_instance; 51 + struct vchiq_state; 51 52 52 53 struct vchiq_service_base { 53 54 int fourcc; ··· 79 78 short version_min; /* Update for incompatible changes */ 80 79 }; 81 80 82 - extern int vchiq_initialise(struct vchiq_instance **pinstance); 81 + extern int vchiq_initialise(struct vchiq_state *state, 82 + struct vchiq_instance **pinstance); 83 83 extern int vchiq_shutdown(struct vchiq_instance *instance); 84 84 extern int vchiq_connect(struct vchiq_instance *instance); 85 85 extern int vchiq_open_service(struct vchiq_instance *instance,
-15
drivers/staging/vc04_services/interface/TODO
··· 28 28 A short top-down description of this driver's architecture (function of 29 29 kthreads, userspace, limitations) could be very helpful for reviewers. 30 30 31 - * Review and comment memory barriers 32 - 33 - There is a heavy use of memory barriers in this driver, it would be very 34 - beneficial to go over all of them and, if correct, comment on their merits. 35 - Extra points to whomever confidently reviews the remote_event_*() family of 36 - functions. 37 - 38 31 * Reformat core code with more sane indentations 39 32 40 33 The code follows the 80 characters limitation yet tends to go 3 or 4 levels of 41 34 indentation deep making it very unpleasant to read. This is specially relevant 42 35 in the character driver ioctl code and in the core thread functions. 43 - 44 - * Get rid of all non essential global structures and create a proper per 45 - device structure 46 - 47 - The first thing one generally sees in a probe function is a memory allocation 48 - for all the device specific data. This structure is then passed all over the 49 - driver. This is good practice since it makes the driver work regardless of the 50 - number of devices probed. 51 36 52 37 * Clean up Sparse warnings from __user annotations. See 53 38 vchiq_irq_queue_bulk_tx_rx(). Ensure that the address of "&waiter->bulk_waiter"
+143 -122
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
··· 36 36 #include "vchiq_arm.h" 37 37 #include "vchiq_bus.h" 38 38 #include "vchiq_debugfs.h" 39 - #include "vchiq_connected.h" 40 39 #include "vchiq_pagelist.h" 41 40 42 41 #define DEVICE_NAME "vchiq" ··· 59 60 #define KEEPALIVE_VER 1 60 61 #define KEEPALIVE_VER_MIN KEEPALIVE_VER 61 62 62 - DEFINE_SPINLOCK(msg_queue_spinlock); 63 - struct vchiq_state g_state; 64 - 65 63 /* 66 64 * The devices implemented in the VCHIQ firmware are not discoverable, 67 65 * so we need to maintain a list of them in order to register them with ··· 67 71 static struct vchiq_device *bcm2835_audio; 68 72 static struct vchiq_device *bcm2835_camera; 69 73 70 - struct vchiq_drvdata { 71 - const unsigned int cache_line_size; 72 - struct rpi_firmware *fw; 73 - }; 74 - 75 - static struct vchiq_drvdata bcm2835_drvdata = { 74 + static const struct vchiq_platform_info bcm2835_info = { 76 75 .cache_line_size = 32, 77 76 }; 78 77 79 - static struct vchiq_drvdata bcm2836_drvdata = { 78 + static const struct vchiq_platform_info bcm2836_info = { 80 79 .cache_line_size = 64, 81 80 }; 82 81 ··· 126 135 unsigned int scatterlist_mapped; 127 136 }; 128 137 129 - static void __iomem *g_regs; 130 - /* This value is the size of the L2 cache lines as understood by the 131 - * VPU firmware, which determines the required alignment of the 132 - * offsets/sizes in pagelists. 133 - * 134 - * Modern VPU firmware looks for a DT "cache-line-size" property in 135 - * the VCHIQ node and will overwrite it with the actual L2 cache size, 136 - * which the kernel must then respect. That property was rejected 137 - * upstream, so we have to use the VPU firmware's compatibility value 138 - * of 32. 139 - */ 140 - static unsigned int g_cache_line_size = 32; 141 - static unsigned int g_fragments_size; 142 - static char *g_fragments_base; 143 - static char *g_free_fragments; 144 - static struct semaphore g_free_fragments_sema; 145 - 146 - static DEFINE_SEMAPHORE(g_free_fragments_mutex, 1); 147 - 148 138 static int 149 139 vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, void *data, 150 140 unsigned int size, enum vchiq_bulk_dir dir); ··· 134 162 vchiq_doorbell_irq(int irq, void *dev_id) 135 163 { 136 164 struct vchiq_state *state = dev_id; 165 + struct vchiq_drv_mgmt *mgmt; 137 166 irqreturn_t ret = IRQ_NONE; 138 167 unsigned int status; 139 168 169 + mgmt = dev_get_drvdata(state->dev); 170 + 140 171 /* Read (and clear) the doorbell */ 141 - status = readl(g_regs + BELL0); 172 + status = readl(mgmt->regs + BELL0); 142 173 143 174 if (status & ARM_DS_ACTIVE) { /* Was the doorbell rung? */ 144 175 remote_event_pollall(state); ··· 180 205 return tmp == (addr & PAGE_MASK); 181 206 } 182 207 208 + /* 209 + * This function is called by the vchiq stack once it has been connected to 210 + * the videocore and clients can start to use the stack. 211 + */ 212 + static void vchiq_call_connected_callbacks(struct vchiq_drv_mgmt *drv_mgmt) 213 + { 214 + int i; 215 + 216 + if (mutex_lock_killable(&drv_mgmt->connected_mutex)) 217 + return; 218 + 219 + for (i = 0; i < drv_mgmt->num_deferred_callbacks; i++) 220 + drv_mgmt->deferred_callback[i](); 221 + 222 + drv_mgmt->num_deferred_callbacks = 0; 223 + drv_mgmt->connected = true; 224 + mutex_unlock(&drv_mgmt->connected_mutex); 225 + } 226 + 227 + /* 228 + * This function is used to defer initialization until the vchiq stack is 229 + * initialized. If the stack is already initialized, then the callback will 230 + * be made immediately, otherwise it will be deferred until 231 + * vchiq_call_connected_callbacks is called. 232 + */ 233 + void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void)) 234 + { 235 + struct vchiq_drv_mgmt *drv_mgmt = device->drv_mgmt; 236 + 237 + if (mutex_lock_killable(&drv_mgmt->connected_mutex)) 238 + return; 239 + 240 + if (drv_mgmt->connected) { 241 + /* We're already connected. Call the callback immediately. */ 242 + callback(); 243 + } else { 244 + if (drv_mgmt->num_deferred_callbacks >= VCHIQ_DRV_MAX_CALLBACKS) { 245 + dev_err(&device->dev, 246 + "core: deferred callbacks(%d) exceeded the maximum limit(%d)\n", 247 + drv_mgmt->num_deferred_callbacks, VCHIQ_DRV_MAX_CALLBACKS); 248 + } else { 249 + drv_mgmt->deferred_callback[drv_mgmt->num_deferred_callbacks] = 250 + callback; 251 + drv_mgmt->num_deferred_callbacks++; 252 + } 253 + } 254 + mutex_unlock(&drv_mgmt->connected_mutex); 255 + } 256 + EXPORT_SYMBOL(vchiq_add_connected_callback); 257 + 183 258 /* There is a potential problem with partial cache lines (pages?) 184 259 * at the ends of the block when reading. If the CPU accessed anything in 185 260 * the same line (page?) then it may have pulled old data into the cache, ··· 242 217 create_pagelist(struct vchiq_instance *instance, char *buf, char __user *ubuf, 243 218 size_t count, unsigned short type) 244 219 { 220 + struct vchiq_drv_mgmt *drv_mgmt; 245 221 struct pagelist *pagelist; 246 222 struct vchiq_pagelist_info *pagelistinfo; 247 223 struct page **pages; ··· 256 230 257 231 if (count >= INT_MAX - PAGE_SIZE) 258 232 return NULL; 233 + 234 + drv_mgmt = dev_get_drvdata(instance->state->dev); 259 235 260 236 if (buf) 261 237 offset = (uintptr_t)buf & (PAGE_SIZE - 1); ··· 401 373 402 374 /* Partial cache lines (fragments) require special measures */ 403 375 if ((type == PAGELIST_READ) && 404 - ((pagelist->offset & (g_cache_line_size - 1)) || 376 + ((pagelist->offset & (drv_mgmt->info->cache_line_size - 1)) || 405 377 ((pagelist->offset + pagelist->length) & 406 - (g_cache_line_size - 1)))) { 378 + (drv_mgmt->info->cache_line_size - 1)))) { 407 379 char *fragments; 408 380 409 - if (down_interruptible(&g_free_fragments_sema)) { 381 + if (down_interruptible(&drv_mgmt->free_fragments_sema)) { 410 382 cleanup_pagelistinfo(instance, pagelistinfo); 411 383 return NULL; 412 384 } 413 385 414 - WARN_ON(!g_free_fragments); 386 + WARN_ON(!drv_mgmt->free_fragments); 415 387 416 - down(&g_free_fragments_mutex); 417 - fragments = g_free_fragments; 388 + down(&drv_mgmt->free_fragments_mutex); 389 + fragments = drv_mgmt->free_fragments; 418 390 WARN_ON(!fragments); 419 - g_free_fragments = *(char **)g_free_fragments; 420 - up(&g_free_fragments_mutex); 391 + drv_mgmt->free_fragments = *(char **)drv_mgmt->free_fragments; 392 + up(&drv_mgmt->free_fragments_mutex); 421 393 pagelist->type = PAGELIST_READ_WITH_FRAGMENTS + 422 - (fragments - g_fragments_base) / g_fragments_size; 394 + (fragments - drv_mgmt->fragments_base) / drv_mgmt->fragments_size; 423 395 } 424 396 425 397 return pagelistinfo; ··· 429 401 free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info *pagelistinfo, 430 402 int actual) 431 403 { 404 + struct vchiq_drv_mgmt *drv_mgmt; 432 405 struct pagelist *pagelist = pagelistinfo->pagelist; 433 406 struct page **pages = pagelistinfo->pages; 434 407 unsigned int num_pages = pagelistinfo->num_pages; 435 408 436 409 dev_dbg(instance->state->dev, "arm: %pK, %d\n", pagelistinfo->pagelist, actual); 410 + 411 + drv_mgmt = dev_get_drvdata(instance->state->dev); 437 412 438 413 /* 439 414 * NOTE: dma_unmap_sg must be called before the ··· 447 416 pagelistinfo->scatterlist_mapped = 0; 448 417 449 418 /* Deal with any partial cache lines (fragments) */ 450 - if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS && g_fragments_base) { 451 - char *fragments = g_fragments_base + 419 + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS && drv_mgmt->fragments_base) { 420 + char *fragments = drv_mgmt->fragments_base + 452 421 (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS) * 453 - g_fragments_size; 422 + drv_mgmt->fragments_size; 454 423 int head_bytes, tail_bytes; 455 424 456 - head_bytes = (g_cache_line_size - pagelist->offset) & 457 - (g_cache_line_size - 1); 425 + head_bytes = (drv_mgmt->info->cache_line_size - pagelist->offset) & 426 + (drv_mgmt->info->cache_line_size - 1); 458 427 tail_bytes = (pagelist->offset + actual) & 459 - (g_cache_line_size - 1); 428 + (drv_mgmt->info->cache_line_size - 1); 460 429 461 430 if ((actual >= 0) && (head_bytes != 0)) { 462 431 if (head_bytes > actual) ··· 471 440 (tail_bytes != 0)) 472 441 memcpy_to_page(pages[num_pages - 1], 473 442 (pagelist->offset + actual) & 474 - (PAGE_SIZE - 1) & ~(g_cache_line_size - 1), 475 - fragments + g_cache_line_size, 443 + (PAGE_SIZE - 1) & ~(drv_mgmt->info->cache_line_size - 1), 444 + fragments + drv_mgmt->info->cache_line_size, 476 445 tail_bytes); 477 446 478 - down(&g_free_fragments_mutex); 479 - *(char **)fragments = g_free_fragments; 480 - g_free_fragments = fragments; 481 - up(&g_free_fragments_mutex); 482 - up(&g_free_fragments_sema); 447 + down(&drv_mgmt->free_fragments_mutex); 448 + *(char **)fragments = drv_mgmt->free_fragments; 449 + drv_mgmt->free_fragments = fragments; 450 + up(&drv_mgmt->free_fragments_mutex); 451 + up(&drv_mgmt->free_fragments_sema); 483 452 } 484 453 485 454 /* Need to mark all the pages dirty. */ ··· 497 466 static int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *state) 498 467 { 499 468 struct device *dev = &pdev->dev; 500 - struct vchiq_drvdata *drvdata = platform_get_drvdata(pdev); 501 - struct rpi_firmware *fw = drvdata->fw; 469 + struct vchiq_drv_mgmt *drv_mgmt = platform_get_drvdata(pdev); 470 + struct rpi_firmware *fw = drv_mgmt->fw; 502 471 struct vchiq_slot_zero *vchiq_slot_zero; 503 472 void *slot_mem; 504 473 dma_addr_t slot_phys; ··· 515 484 if (err < 0) 516 485 return err; 517 486 518 - g_cache_line_size = drvdata->cache_line_size; 519 - g_fragments_size = 2 * g_cache_line_size; 487 + drv_mgmt->fragments_size = 2 * drv_mgmt->info->cache_line_size; 520 488 521 489 /* Allocate space for the channels in coherent memory */ 522 490 slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE); 523 - frag_mem_size = PAGE_ALIGN(g_fragments_size * MAX_FRAGMENTS); 491 + frag_mem_size = PAGE_ALIGN(drv_mgmt->fragments_size * MAX_FRAGMENTS); 524 492 525 493 slot_mem = dmam_alloc_coherent(dev, slot_mem_size + frag_mem_size, 526 494 &slot_phys, GFP_KERNEL); ··· 539 509 vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] = 540 510 MAX_FRAGMENTS; 541 511 542 - g_fragments_base = (char *)slot_mem + slot_mem_size; 512 + drv_mgmt->fragments_base = (char *)slot_mem + slot_mem_size; 543 513 544 - g_free_fragments = g_fragments_base; 514 + drv_mgmt->free_fragments = drv_mgmt->fragments_base; 545 515 for (i = 0; i < (MAX_FRAGMENTS - 1); i++) { 546 - *(char **)&g_fragments_base[i * g_fragments_size] = 547 - &g_fragments_base[(i + 1) * g_fragments_size]; 516 + *(char **)&drv_mgmt->fragments_base[i * drv_mgmt->fragments_size] = 517 + &drv_mgmt->fragments_base[(i + 1) * drv_mgmt->fragments_size]; 548 518 } 549 - *(char **)&g_fragments_base[i * g_fragments_size] = NULL; 550 - sema_init(&g_free_fragments_sema, MAX_FRAGMENTS); 519 + *(char **)&drv_mgmt->fragments_base[i * drv_mgmt->fragments_size] = NULL; 520 + sema_init(&drv_mgmt->free_fragments_sema, MAX_FRAGMENTS); 521 + sema_init(&drv_mgmt->free_fragments_mutex, 1); 551 522 552 523 err = vchiq_init_state(state, vchiq_slot_zero, dev); 553 524 if (err) 554 525 return err; 555 526 556 - g_regs = devm_platform_ioremap_resource(pdev, 0); 557 - if (IS_ERR(g_regs)) 558 - return PTR_ERR(g_regs); 527 + drv_mgmt->regs = devm_platform_ioremap_resource(pdev, 0); 528 + if (IS_ERR(drv_mgmt->regs)) 529 + return PTR_ERR(drv_mgmt->regs); 559 530 560 531 irq = platform_get_irq(pdev, 0); 561 532 if (irq <= 0) ··· 587 556 dev_dbg(&pdev->dev, "arm: vchiq_init - done (slots %pK, phys %pad)\n", 588 557 vchiq_slot_zero, &slot_phys); 589 558 590 - vchiq_call_connected_callbacks(); 559 + mutex_init(&drv_mgmt->connected_mutex); 560 + vchiq_call_connected_callbacks(drv_mgmt); 591 561 592 562 return 0; 593 563 } ··· 639 607 } 640 608 641 609 void 642 - remote_event_signal(struct remote_event *event) 610 + remote_event_signal(struct vchiq_state *state, struct remote_event *event) 643 611 { 612 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(state->dev); 613 + 644 614 /* 645 615 * Ensure that all writes to shared data structures have completed 646 616 * before signalling the peer. ··· 654 620 dsb(sy); /* data barrier operation */ 655 621 656 622 if (event->armed) 657 - writel(0, g_regs + BELL2); /* trigger vc interrupt */ 623 + writel(0, mgmt->regs + BELL2); /* trigger vc interrupt */ 658 624 } 659 625 660 626 int ··· 696 662 } 697 663 698 664 #define VCHIQ_INIT_RETRIES 10 699 - int vchiq_initialise(struct vchiq_instance **instance_out) 665 + int vchiq_initialise(struct vchiq_state *state, struct vchiq_instance **instance_out) 700 666 { 701 - struct vchiq_state *state; 702 667 struct vchiq_instance *instance = NULL; 703 668 int i, ret; 704 669 ··· 707 674 * block forever. 708 675 */ 709 676 for (i = 0; i < VCHIQ_INIT_RETRIES; i++) { 710 - state = vchiq_get_state(); 711 677 if (state) 712 678 break; 713 679 usleep_range(500, 600); ··· 722 690 723 691 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 724 692 if (!instance) { 725 - dev_err(state->dev, "core: %s: Cannot allocate vchiq instance\n", __func__); 726 693 ret = -ENOMEM; 727 694 goto failed; 728 695 } ··· 980 949 * This is not a retry of the previous one. 981 950 * Cancel the signal when the transfer completes. 982 951 */ 983 - spin_lock(&bulk_waiter_spinlock); 952 + spin_lock(&service->state->bulk_waiter_spinlock); 984 953 bulk->userdata = NULL; 985 - spin_unlock(&bulk_waiter_spinlock); 954 + spin_unlock(&service->state->bulk_waiter_spinlock); 986 955 } 987 956 } 988 957 } else { 989 958 waiter = kzalloc(sizeof(*waiter), GFP_KERNEL); 990 - if (!waiter) { 991 - dev_err(service->state->dev, "core: %s: - Out of memory\n", __func__); 959 + if (!waiter) 992 960 return -ENOMEM; 993 - } 994 961 } 995 962 996 963 status = vchiq_bulk_transfer(instance, handle, data, NULL, size, ··· 999 970 1000 971 if (bulk) { 1001 972 /* Cancel the signal when the transfer completes. */ 1002 - spin_lock(&bulk_waiter_spinlock); 973 + spin_lock(&service->state->bulk_waiter_spinlock); 1003 974 bulk->userdata = NULL; 1004 - spin_unlock(&bulk_waiter_spinlock); 975 + spin_unlock(&service->state->bulk_waiter_spinlock); 1005 976 } 1006 977 kfree(waiter); 1007 978 } else { ··· 1022 993 void *bulk_userdata) 1023 994 { 1024 995 struct vchiq_completion_data_kernel *completion; 996 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(instance->state->dev); 1025 997 int insert; 1026 998 1027 - DEBUG_INITIALISE(g_state.local); 999 + DEBUG_INITIALISE(mgmt->state.local); 1028 1000 1029 1001 insert = instance->completion_insert; 1030 1002 while ((insert - instance->completion_remove) >= MAX_COMPLETIONS) { ··· 1088 1058 * containing the original callback and the user state structure, which 1089 1059 * contains a circular buffer for completion records. 1090 1060 */ 1061 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(instance->state->dev); 1091 1062 struct user_service *user_service; 1092 1063 struct vchiq_service *service; 1093 1064 bool skip_completion = false; 1094 1065 1095 - DEBUG_INITIALISE(g_state.local); 1066 + DEBUG_INITIALISE(mgmt->state.local); 1096 1067 1097 1068 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 1098 1069 ··· 1106 1075 1107 1076 user_service = (struct user_service *)service->base.userdata; 1108 1077 1109 - if (!instance || instance->closing) { 1078 + if (instance->closing) { 1110 1079 rcu_read_unlock(); 1111 1080 return 0; 1112 1081 } ··· 1124 1093 reason, header, instance, bulk_userdata); 1125 1094 1126 1095 if (header && user_service->is_vchi) { 1127 - spin_lock(&msg_queue_spinlock); 1096 + spin_lock(&service->state->msg_queue_spinlock); 1128 1097 while (user_service->msg_insert == 1129 1098 (user_service->msg_remove + MSG_QUEUE_SIZE)) { 1130 - spin_unlock(&msg_queue_spinlock); 1099 + spin_unlock(&service->state->msg_queue_spinlock); 1131 1100 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 1132 1101 DEBUG_COUNT(MSG_QUEUE_FULL_COUNT); 1133 1102 dev_dbg(service->state->dev, "arm: msg queue full\n"); ··· 1164 1133 return -EINVAL; 1165 1134 } 1166 1135 DEBUG_TRACE(SERVICE_CALLBACK_LINE); 1167 - spin_lock(&msg_queue_spinlock); 1136 + spin_lock(&service->state->msg_queue_spinlock); 1168 1137 } 1169 1138 1170 1139 user_service->msg_queue[user_service->msg_insert & ··· 1183 1152 skip_completion = true; 1184 1153 } 1185 1154 1186 - spin_unlock(&msg_queue_spinlock); 1155 + spin_unlock(&service->state->msg_queue_spinlock); 1187 1156 complete(&user_service->insert_event); 1188 1157 1189 1158 header = NULL; ··· 1198 1167 bulk_userdata); 1199 1168 } 1200 1169 1201 - void vchiq_dump_platform_instances(struct seq_file *f) 1170 + void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f) 1202 1171 { 1203 - struct vchiq_state *state = vchiq_get_state(); 1204 1172 int i; 1205 1173 1206 1174 if (!state) ··· 1274 1244 seq_puts(f, "\n"); 1275 1245 } 1276 1246 1277 - struct vchiq_state * 1278 - vchiq_get_state(void) 1279 - { 1280 - if (!g_state.remote) { 1281 - pr_err("%s: g_state.remote == NULL\n", __func__); 1282 - return NULL; 1283 - } 1284 - 1285 - if (g_state.remote->initialised != 1) { 1286 - pr_notice("%s: g_state.remote->initialised != 1 (%d)\n", 1287 - __func__, g_state.remote->initialised); 1288 - return NULL; 1289 - } 1290 - 1291 - return &g_state; 1292 - } 1293 - 1294 1247 /* 1295 1248 * Autosuspend related functionality 1296 1249 */ ··· 1307 1294 .version_min = KEEPALIVE_VER_MIN 1308 1295 }; 1309 1296 1310 - ret = vchiq_initialise(&instance); 1297 + ret = vchiq_initialise(state, &instance); 1311 1298 if (ret) { 1312 1299 dev_err(state->dev, "suspend: %s: vchiq_initialise failed %d\n", __func__, ret); 1313 1300 goto exit; ··· 1330 1317 long rc = 0, uc = 0; 1331 1318 1332 1319 if (wait_for_completion_interruptible(&arm_state->ka_evt)) { 1333 - dev_err(state->dev, "suspend: %s: interrupted\n", __func__); 1320 + dev_dbg(state->dev, "suspend: %s: interrupted\n", __func__); 1334 1321 flush_signals(current); 1335 1322 continue; 1336 1323 } ··· 1719 1706 } 1720 1707 1721 1708 static const struct of_device_id vchiq_of_match[] = { 1722 - { .compatible = "brcm,bcm2835-vchiq", .data = &bcm2835_drvdata }, 1723 - { .compatible = "brcm,bcm2836-vchiq", .data = &bcm2836_drvdata }, 1709 + { .compatible = "brcm,bcm2835-vchiq", .data = &bcm2835_info }, 1710 + { .compatible = "brcm,bcm2836-vchiq", .data = &bcm2836_info }, 1724 1711 {}, 1725 1712 }; 1726 1713 MODULE_DEVICE_TABLE(of, vchiq_of_match); ··· 1728 1715 static int vchiq_probe(struct platform_device *pdev) 1729 1716 { 1730 1717 struct device_node *fw_node; 1731 - const struct of_device_id *of_id; 1732 - struct vchiq_drvdata *drvdata; 1718 + const struct vchiq_platform_info *info; 1719 + struct vchiq_drv_mgmt *mgmt; 1733 1720 int err; 1734 1721 1735 - of_id = of_match_node(vchiq_of_match, pdev->dev.of_node); 1736 - drvdata = (struct vchiq_drvdata *)of_id->data; 1737 - if (!drvdata) 1722 + info = of_device_get_match_data(&pdev->dev); 1723 + if (!info) 1738 1724 return -EINVAL; 1739 1725 1740 1726 fw_node = of_find_compatible_node(NULL, NULL, ··· 1743 1731 return -ENOENT; 1744 1732 } 1745 1733 1746 - drvdata->fw = devm_rpi_firmware_get(&pdev->dev, fw_node); 1734 + mgmt = kzalloc(sizeof(*mgmt), GFP_KERNEL); 1735 + if (!mgmt) 1736 + return -ENOMEM; 1737 + 1738 + mgmt->fw = devm_rpi_firmware_get(&pdev->dev, fw_node); 1747 1739 of_node_put(fw_node); 1748 - if (!drvdata->fw) 1740 + if (!mgmt->fw) 1749 1741 return -EPROBE_DEFER; 1750 1742 1751 - platform_set_drvdata(pdev, drvdata); 1743 + mgmt->info = info; 1744 + platform_set_drvdata(pdev, mgmt); 1752 1745 1753 - err = vchiq_platform_init(pdev, &g_state); 1746 + err = vchiq_platform_init(pdev, &mgmt->state); 1754 1747 if (err) 1755 1748 goto failed_platform_init; 1756 1749 ··· 1770 1753 */ 1771 1754 err = vchiq_register_chrdev(&pdev->dev); 1772 1755 if (err) { 1773 - dev_warn(&pdev->dev, "arm: Failed to initialize vchiq cdev\n"); 1756 + dev_err(&pdev->dev, "arm: Failed to initialize vchiq cdev\n"); 1774 1757 goto error_exit; 1775 1758 } 1776 1759 ··· 1780 1763 return 0; 1781 1764 1782 1765 failed_platform_init: 1783 - dev_warn(&pdev->dev, "arm: Could not initialize vchiq platform\n"); 1766 + dev_err(&pdev->dev, "arm: Could not initialize vchiq platform\n"); 1784 1767 error_exit: 1785 1768 return err; 1786 1769 } 1787 1770 1788 1771 static void vchiq_remove(struct platform_device *pdev) 1789 1772 { 1773 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(&pdev->dev); 1774 + 1790 1775 vchiq_device_unregister(bcm2835_audio); 1791 1776 vchiq_device_unregister(bcm2835_camera); 1792 1777 vchiq_debugfs_deinit(); 1793 1778 vchiq_deregister_chrdev(); 1779 + 1780 + kfree(mgmt); 1794 1781 } 1795 1782 1796 1783 static struct platform_driver vchiq_driver = {
+35 -6
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
··· 20 20 #define MAX_ELEMENTS 8 21 21 #define MSG_QUEUE_SIZE 128 22 22 23 + #define VCHIQ_DRV_MAX_CALLBACKS 10 24 + 25 + struct rpi_firmware; 26 + struct vchiq_device; 27 + 23 28 enum USE_TYPE_E { 24 29 USE_TYPE_SERVICE, 25 30 USE_TYPE_VCHIQ 31 + }; 32 + 33 + struct vchiq_platform_info { 34 + unsigned int cache_line_size; 35 + }; 36 + 37 + struct vchiq_drv_mgmt { 38 + struct rpi_firmware *fw; 39 + const struct vchiq_platform_info *info; 40 + 41 + bool connected; 42 + int num_deferred_callbacks; 43 + /* Protects connected and num_deferred_callbacks */ 44 + struct mutex connected_mutex; 45 + 46 + void (*deferred_callback[VCHIQ_DRV_MAX_CALLBACKS])(void); 47 + 48 + struct semaphore free_fragments_sema; 49 + struct semaphore free_fragments_mutex; 50 + char *fragments_base; 51 + char *free_fragments; 52 + unsigned int fragments_size; 53 + 54 + void __iomem *regs; 55 + 56 + struct vchiq_state state; 26 57 }; 27 58 28 59 struct user_service { ··· 100 69 struct vchiq_debugfs_node debugfs_node; 101 70 }; 102 71 103 - extern spinlock_t msg_queue_spinlock; 104 - extern struct vchiq_state g_state; 105 - 106 - extern struct vchiq_state * 107 - vchiq_get_state(void); 108 - 109 72 int 110 73 vchiq_use_service(struct vchiq_instance *instance, unsigned int handle); 111 74 ··· 136 111 137 112 extern void 138 113 vchiq_instance_set_trace(struct vchiq_instance *instance, int trace); 114 + 115 + extern void 116 + vchiq_add_connected_callback(struct vchiq_device *device, 117 + void (*callback)(void)); 139 118 140 119 #if IS_ENABLED(CONFIG_VCHIQ_CDEV) 141 120
+13
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_bus.c
··· 11 11 #include <linux/slab.h> 12 12 #include <linux/string.h> 13 13 14 + #include "vchiq_arm.h" 14 15 #include "vchiq_bus.h" 15 16 16 17 static int vchiq_bus_type_match(struct device *dev, struct device_driver *drv) ··· 38 37 return driver->probe(device); 39 38 } 40 39 40 + static void vchiq_bus_remove(struct device *dev) 41 + { 42 + struct vchiq_device *device = to_vchiq_device(dev); 43 + struct vchiq_driver *driver = to_vchiq_driver(dev->driver); 44 + 45 + if (driver->remove) 46 + driver->remove(device); 47 + } 48 + 41 49 const struct bus_type vchiq_bus_type = { 42 50 .name = "vchiq-bus", 43 51 .match = vchiq_bus_type_match, 44 52 .uevent = vchiq_bus_uevent, 45 53 .probe = vchiq_bus_probe, 54 + .remove = vchiq_bus_remove, 46 55 }; 47 56 48 57 static void vchiq_device_release(struct device *dev) ··· 77 66 device->dev.bus = &vchiq_bus_type; 78 67 device->dev.dma_mask = &device->dev.coherent_dma_mask; 79 68 device->dev.release = vchiq_device_release; 69 + 70 + device->drv_mgmt = dev_get_drvdata(parent); 80 71 81 72 of_dma_configure(&device->dev, parent->of_node, true); 82 73
+3
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_bus.h
··· 9 9 #include <linux/device.h> 10 10 #include <linux/mod_devicetable.h> 11 11 12 + struct vchiq_drv_mgmt; 13 + 12 14 struct vchiq_device { 13 15 struct device dev; 16 + struct vchiq_drv_mgmt *drv_mgmt; 14 17 }; 15 18 16 19 struct vchiq_driver {
-74
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 - /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */ 3 - 4 - #include "vchiq_connected.h" 5 - #include "vchiq_core.h" 6 - #include <linux/module.h> 7 - #include <linux/mutex.h> 8 - 9 - #define MAX_CALLBACKS 10 10 - 11 - static int g_connected; 12 - static int g_num_deferred_callbacks; 13 - static void (*g_deferred_callback[MAX_CALLBACKS])(void); 14 - static int g_once_init; 15 - static DEFINE_MUTEX(g_connected_mutex); 16 - 17 - /* Function to initialize our lock */ 18 - static void connected_init(void) 19 - { 20 - if (!g_once_init) 21 - g_once_init = 1; 22 - } 23 - 24 - /* 25 - * This function is used to defer initialization until the vchiq stack is 26 - * initialized. If the stack is already initialized, then the callback will 27 - * be made immediately, otherwise it will be deferred until 28 - * vchiq_call_connected_callbacks is called. 29 - */ 30 - void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void)) 31 - { 32 - connected_init(); 33 - 34 - if (mutex_lock_killable(&g_connected_mutex)) 35 - return; 36 - 37 - if (g_connected) { 38 - /* We're already connected. Call the callback immediately. */ 39 - callback(); 40 - } else { 41 - if (g_num_deferred_callbacks >= MAX_CALLBACKS) { 42 - dev_err(&device->dev, 43 - "core: There already %d callback registered - please increase MAX_CALLBACKS\n", 44 - g_num_deferred_callbacks); 45 - } else { 46 - g_deferred_callback[g_num_deferred_callbacks] = 47 - callback; 48 - g_num_deferred_callbacks++; 49 - } 50 - } 51 - mutex_unlock(&g_connected_mutex); 52 - } 53 - EXPORT_SYMBOL(vchiq_add_connected_callback); 54 - 55 - /* 56 - * This function is called by the vchiq stack once it has been connected to 57 - * the videocore and clients can start to use the stack. 58 - */ 59 - void vchiq_call_connected_callbacks(void) 60 - { 61 - int i; 62 - 63 - connected_init(); 64 - 65 - if (mutex_lock_killable(&g_connected_mutex)) 66 - return; 67 - 68 - for (i = 0; i < g_num_deferred_callbacks; i++) 69 - g_deferred_callback[i](); 70 - 71 - g_num_deferred_callbacks = 0; 72 - g_connected = 1; 73 - mutex_unlock(&g_connected_mutex); 74 - }
-12
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_connected.h
··· 1 - /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 2 - /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */ 3 - 4 - #include "vchiq_bus.h" 5 - 6 - #ifndef VCHIQ_CONNECTED_H 7 - #define VCHIQ_CONNECTED_H 8 - 9 - void vchiq_add_connected_callback(struct vchiq_device *device, void (*callback)(void)); 10 - void vchiq_call_connected_callbacks(void); 11 - 12 - #endif /* VCHIQ_CONNECTED_H */
+34 -33
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
··· 43 43 (((type) << TYPE_SHIFT) | ((srcport) << 12) | ((dstport) << 0)) 44 44 #define VCHIQ_MSG_TYPE(msgid) ((unsigned int)(msgid) >> TYPE_SHIFT) 45 45 #define VCHIQ_MSG_SRCPORT(msgid) \ 46 - (unsigned short)(((unsigned int)(msgid) >> 12) & 0xfff) 46 + ((unsigned short)(((unsigned int)(msgid) >> 12) & 0xfff)) 47 47 #define VCHIQ_MSG_DSTPORT(msgid) \ 48 48 ((unsigned short)(msgid) & 0xfff) 49 49 ··· 149 149 BUILD_BUG_ON_NOT_POWER_OF_2(VCHIQ_MAX_SERVICES); 150 150 } 151 151 152 - DEFINE_SPINLOCK(bulk_waiter_spinlock); 153 - static DEFINE_SPINLOCK(quota_spinlock); 154 - 155 152 static unsigned int handle_seq; 156 153 157 154 static const char *const srvstate_names[] = { ··· 227 230 228 231 return rcu_dereference(instance->state->services[idx]); 229 232 } 233 + 230 234 struct vchiq_service * 231 235 find_service_by_handle(struct vchiq_instance *instance, unsigned int handle) 232 236 { ··· 689 691 /* But first, flush through the last slot. */ 690 692 state->local_tx_pos = tx_pos; 691 693 local->tx_pos = tx_pos; 692 - remote_event_signal(&state->remote->trigger); 694 + remote_event_signal(state, &state->remote->trigger); 693 695 694 696 if (!is_blocking || 695 697 (wait_for_completion_interruptible(&state->slot_available_event))) ··· 698 700 699 701 if (tx_pos == (state->slot_queue_available * VCHIQ_SLOT_SIZE)) { 700 702 complete(&state->slot_available_event); 701 - pr_warn("%s: invalid tx_pos: %d\n", __func__, tx_pos); 703 + dev_warn(state->dev, "%s: invalid tx_pos: %d\n", 704 + __func__, tx_pos); 702 705 return NULL; 703 706 } 704 707 ··· 723 724 struct vchiq_service_quota *quota = &state->service_quotas[port]; 724 725 int count; 725 726 726 - spin_lock(&quota_spinlock); 727 + spin_lock(&state->quota_spinlock); 727 728 count = quota->message_use_count; 728 729 if (count > 0) 729 730 quota->message_use_count = count - 1; 730 - spin_unlock(&quota_spinlock); 731 + spin_unlock(&state->quota_spinlock); 731 732 732 733 if (count == quota->message_quota) { 733 734 /* ··· 746 747 /* Set the found bit for this service */ 747 748 BITSET_SET(service_found, port); 748 749 749 - spin_lock(&quota_spinlock); 750 + spin_lock(&state->quota_spinlock); 750 751 count = quota->slot_use_count; 751 752 if (count > 0) 752 753 quota->slot_use_count = count - 1; 753 - spin_unlock(&quota_spinlock); 754 + spin_unlock(&state->quota_spinlock); 754 755 755 756 if (count > 0) { 756 757 /* ··· 836 837 if (data_found) { 837 838 int count; 838 839 839 - spin_lock(&quota_spinlock); 840 + spin_lock(&state->quota_spinlock); 840 841 count = state->data_use_count; 841 842 if (count > 0) 842 843 state->data_use_count = count - 1; 843 - spin_unlock(&quota_spinlock); 844 + spin_unlock(&state->quota_spinlock); 844 845 if (count == state->data_quota) 845 846 complete(&state->data_quota_event); 846 847 } ··· 939 940 940 941 quota = &state->service_quotas[service->localport]; 941 942 942 - spin_lock(&quota_spinlock); 943 + spin_lock(&state->quota_spinlock); 943 944 944 945 /* 945 946 * Ensure this service doesn't use more than its quota of ··· 954 955 while ((tx_end_index != state->previous_data_index) && 955 956 (state->data_use_count == state->data_quota)) { 956 957 VCHIQ_STATS_INC(state, data_stalls); 957 - spin_unlock(&quota_spinlock); 958 + spin_unlock(&state->quota_spinlock); 958 959 mutex_unlock(&state->slot_mutex); 959 960 960 961 if (wait_for_completion_interruptible(&state->data_quota_event)) 961 962 return -EAGAIN; 962 963 963 964 mutex_lock(&state->slot_mutex); 964 - spin_lock(&quota_spinlock); 965 + spin_lock(&state->quota_spinlock); 965 966 tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos + stride - 1); 966 967 if ((tx_end_index == state->previous_data_index) || 967 968 (state->data_use_count < state->data_quota)) { ··· 974 975 while ((quota->message_use_count == quota->message_quota) || 975 976 ((tx_end_index != quota->previous_tx_index) && 976 977 (quota->slot_use_count == quota->slot_quota))) { 977 - spin_unlock(&quota_spinlock); 978 + spin_unlock(&state->quota_spinlock); 978 979 dev_dbg(state->dev, 979 980 "core: %d: qm:%d %s,%zx - quota stall (msg %d, slot %d)\n", 980 981 state->id, service->localport, msg_type_str(type), size, ··· 992 993 mutex_unlock(&state->slot_mutex); 993 994 return -EHOSTDOWN; 994 995 } 995 - spin_lock(&quota_spinlock); 996 + spin_lock(&state->quota_spinlock); 996 997 tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos + stride - 1); 997 998 } 998 999 999 - spin_unlock(&quota_spinlock); 1000 + spin_unlock(&state->quota_spinlock); 1000 1001 } 1001 1002 1002 1003 header = reserve_space(state, stride, flags & QMFLAGS_IS_BLOCKING); ··· 1039 1040 header->data, 1040 1041 min_t(size_t, 16, callback_result)); 1041 1042 1042 - spin_lock(&quota_spinlock); 1043 + spin_lock(&state->quota_spinlock); 1043 1044 quota->message_use_count++; 1044 1045 1045 1046 tx_end_index = ··· 1065 1066 slot_use_count = 0; 1066 1067 } 1067 1068 1068 - spin_unlock(&quota_spinlock); 1069 + spin_unlock(&state->quota_spinlock); 1069 1070 1070 1071 if (slot_use_count) 1071 1072 dev_dbg(state->dev, "core: %d: qm:%d %s,%zx - slot_use->%d (hdr %p)\n", ··· 1123 1124 if (!(flags & QMFLAGS_NO_MUTEX_UNLOCK)) 1124 1125 mutex_unlock(&state->slot_mutex); 1125 1126 1126 - remote_event_signal(&state->remote->trigger); 1127 + remote_event_signal(state, &state->remote->trigger); 1127 1128 1128 1129 return 0; 1129 1130 } ··· 1191 1192 header->size = size; 1192 1193 header->msgid = msgid; 1193 1194 1194 - 1195 1195 svc_fourcc = service ? service->base.fourcc 1196 1196 : VCHIQ_MAKE_FOURCC('?', '?', '?', '?'); 1197 1197 ··· 1200 1202 &svc_fourcc, VCHIQ_MSG_SRCPORT(msgid), 1201 1203 VCHIQ_MSG_DSTPORT(msgid), size); 1202 1204 1203 - remote_event_signal(&state->remote->sync_trigger); 1205 + remote_event_signal(state, &state->remote->sync_trigger); 1204 1206 1205 1207 if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE) 1206 1208 mutex_unlock(&state->sync_mutex); ··· 1258 1260 * A write barrier is necessary, but remote_event_signal 1259 1261 * contains one. 1260 1262 */ 1261 - remote_event_signal(&state->remote->recycle); 1263 + remote_event_signal(state, &state->remote->recycle); 1262 1264 } 1263 1265 1264 1266 mutex_unlock(&state->recycle_mutex); ··· 1320 1322 if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) { 1321 1323 struct bulk_waiter *waiter; 1322 1324 1323 - spin_lock(&bulk_waiter_spinlock); 1325 + spin_lock(&service->state->bulk_waiter_spinlock); 1324 1326 waiter = bulk->userdata; 1325 1327 if (waiter) { 1326 1328 waiter->actual = bulk->actual; 1327 1329 complete(&waiter->event); 1328 1330 } 1329 - spin_unlock(&bulk_waiter_spinlock); 1331 + spin_unlock(&service->state->bulk_waiter_spinlock); 1330 1332 } else if (bulk->mode == VCHIQ_BULK_MODE_CALLBACK) { 1331 1333 enum vchiq_reason reason = 1332 1334 get_bulk_reason(bulk); ··· 1616 1618 break; 1617 1619 } 1618 1620 1619 - 1620 1621 svc_fourcc = service ? service->base.fourcc 1621 1622 : VCHIQ_MAKE_FOURCC('?', '?', '?', '?'); 1622 1623 ··· 1732 1735 break; 1733 1736 } 1734 1737 if (queue->process != queue->remote_insert) { 1735 - pr_err("%s: p %x != ri %x\n", 1736 - __func__, 1737 - queue->process, 1738 - queue->remote_insert); 1738 + dev_err(state->dev, "%s: p %x != ri %x\n", 1739 + __func__, queue->process, 1740 + queue->remote_insert); 1739 1741 mutex_unlock(&service->bulk_mutex); 1740 1742 goto bail_not_ready; 1741 1743 } ··· 2165 2169 mutex_init(&state->sync_mutex); 2166 2170 mutex_init(&state->bulk_transfer_mutex); 2167 2171 2172 + spin_lock_init(&state->msg_queue_spinlock); 2173 + spin_lock_init(&state->bulk_waiter_spinlock); 2174 + spin_lock_init(&state->quota_spinlock); 2175 + 2168 2176 init_completion(&state->slot_available_event); 2169 2177 init_completion(&state->slot_remove_event); 2170 2178 init_completion(&state->data_quota_event); ··· 2177 2177 2178 2178 for (i = 0; i < VCHIQ_MAX_SERVICES; i++) { 2179 2179 struct vchiq_service_quota *quota = &state->service_quotas[i]; 2180 + 2180 2181 init_completion(&quota->quota_event); 2181 2182 } 2182 2183 ··· 3241 3240 release_message_sync(struct vchiq_state *state, struct vchiq_header *header) 3242 3241 { 3243 3242 header->msgid = VCHIQ_MSGID_PADDING; 3244 - remote_event_signal(&state->remote->sync_release); 3243 + remote_event_signal(state, &state->remote->sync_release); 3245 3244 } 3246 3245 3247 3246 int ··· 3505 3504 3506 3505 vchiq_dump_shared_state(f, state, state->remote, "Remote"); 3507 3506 3508 - vchiq_dump_platform_instances(f); 3507 + vchiq_dump_platform_instances(state, f); 3509 3508 3510 3509 for (i = 0; i < state->unused_service; i++) { 3511 3510 struct vchiq_service *service = find_service_by_port(state, i);
+9 -8
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
··· 11 11 #include <linux/kthread.h> 12 12 #include <linux/kref.h> 13 13 #include <linux/rcupdate.h> 14 + #include <linux/spinlock_types.h> 14 15 #include <linux/wait.h> 15 16 16 17 #include "../../include/linux/raspberrypi/vchiq.h" ··· 349 348 350 349 struct mutex bulk_transfer_mutex; 351 350 351 + spinlock_t msg_queue_spinlock; 352 + 353 + spinlock_t bulk_waiter_spinlock; 354 + 355 + spinlock_t quota_spinlock; 356 + 352 357 /* 353 358 * Indicates the byte position within the stream from where the next 354 359 * message will be read. The least significant bits are an index into ··· 478 471 vchiq_dump_state(struct seq_file *f, struct vchiq_state *state); 479 472 480 473 extern void 481 - vchiq_loud_error_header(void); 482 - 483 - extern void 484 - vchiq_loud_error_footer(void); 485 - 486 - extern void 487 474 request_poll(struct vchiq_state *state, struct vchiq_service *service, 488 475 int poll_type); 489 476 ··· 523 522 524 523 void vchiq_complete_bulk(struct vchiq_instance *instance, struct vchiq_bulk *bulk); 525 524 526 - void remote_event_signal(struct remote_event *event); 525 + void remote_event_signal(struct vchiq_state *state, struct remote_event *event); 527 526 528 527 void vchiq_dump_platform_state(struct seq_file *f); 529 528 530 - void vchiq_dump_platform_instances(struct seq_file *f); 529 + void vchiq_dump_platform_instances(struct vchiq_state *state, struct seq_file *f); 531 530 532 531 void vchiq_dump_platform_service_state(struct seq_file *f, struct vchiq_service *service); 533 532
+4 -1
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_debugfs.c
··· 42 42 43 43 static int vchiq_dump_show(struct seq_file *f, void *offset) 44 44 { 45 - vchiq_dump_state(f, &g_state); 45 + struct vchiq_instance *instance = f->private; 46 + 47 + vchiq_dump_state(f, instance->state); 48 + 46 49 return 0; 47 50 } 48 51 DEFINE_SHOW_ATTRIBUTE(vchiq_dump);
+18 -21
drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c
··· 208 208 struct vchiq_header *header; 209 209 int ret; 210 210 211 - DEBUG_INITIALISE(g_state.local); 211 + DEBUG_INITIALISE(instance->state->local); 212 212 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE); 213 213 service = find_service_for_instance(instance, args->handle); 214 214 if (!service) ··· 220 220 goto out; 221 221 } 222 222 223 - spin_lock(&msg_queue_spinlock); 223 + spin_lock(&service->state->msg_queue_spinlock); 224 224 if (user_service->msg_remove == user_service->msg_insert) { 225 225 if (!args->blocking) { 226 - spin_unlock(&msg_queue_spinlock); 226 + spin_unlock(&service->state->msg_queue_spinlock); 227 227 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE); 228 228 ret = -EWOULDBLOCK; 229 229 goto out; ··· 231 231 user_service->dequeue_pending = 1; 232 232 ret = 0; 233 233 do { 234 - spin_unlock(&msg_queue_spinlock); 234 + spin_unlock(&service->state->msg_queue_spinlock); 235 235 DEBUG_TRACE(DEQUEUE_MESSAGE_LINE); 236 236 if (wait_for_completion_interruptible(&user_service->insert_event)) { 237 237 dev_dbg(service->state->dev, "arm: DEQUEUE_MESSAGE interrupted\n"); 238 238 ret = -EINTR; 239 239 break; 240 240 } 241 - spin_lock(&msg_queue_spinlock); 241 + spin_lock(&service->state->msg_queue_spinlock); 242 242 } while (user_service->msg_remove == user_service->msg_insert); 243 243 244 244 if (ret) ··· 247 247 248 248 if (WARN_ON_ONCE((int)(user_service->msg_insert - 249 249 user_service->msg_remove) < 0)) { 250 - spin_unlock(&msg_queue_spinlock); 250 + spin_unlock(&service->state->msg_queue_spinlock); 251 251 ret = -EINVAL; 252 252 goto out; 253 253 } ··· 255 255 header = user_service->msg_queue[user_service->msg_remove & 256 256 (MSG_QUEUE_SIZE - 1)]; 257 257 user_service->msg_remove++; 258 - spin_unlock(&msg_queue_spinlock); 258 + spin_unlock(&service->state->msg_queue_spinlock); 259 259 260 260 complete(&user_service->remove_event); 261 261 if (!header) { ··· 340 340 !waiter->bulk_waiter.bulk) { 341 341 if (waiter->bulk_waiter.bulk) { 342 342 /* Cancel the signal when the transfer completes. */ 343 - spin_lock(&bulk_waiter_spinlock); 343 + spin_lock(&service->state->bulk_waiter_spinlock); 344 344 waiter->bulk_waiter.bulk->userdata = NULL; 345 - spin_unlock(&bulk_waiter_spinlock); 345 + spin_unlock(&service->state->bulk_waiter_spinlock); 346 346 } 347 347 kfree(waiter); 348 348 ret = 0; ··· 435 435 int remove; 436 436 int ret; 437 437 438 - DEBUG_INITIALISE(g_state.local); 438 + DEBUG_INITIALISE(instance->state->local); 439 439 440 440 DEBUG_TRACE(AWAIT_COMPLETION_LINE); 441 441 if (!instance->connected) ··· 1163 1163 1164 1164 static int vchiq_open(struct inode *inode, struct file *file) 1165 1165 { 1166 - struct vchiq_state *state = vchiq_get_state(); 1166 + struct miscdevice *vchiq_miscdev = file->private_data; 1167 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(vchiq_miscdev->parent); 1168 + struct vchiq_state *state = &mgmt->state; 1167 1169 struct vchiq_instance *instance; 1168 1170 1169 1171 dev_dbg(state->dev, "arm: vchiq open\n"); 1170 - 1171 - if (!state) { 1172 - dev_err(state->dev, "arm: vchiq has no connection to VideoCore\n"); 1173 - return -ENOTCONN; 1174 - } 1175 1172 1176 1173 instance = kzalloc(sizeof(*instance), GFP_KERNEL); 1177 1174 if (!instance) ··· 1193 1196 static int vchiq_release(struct inode *inode, struct file *file) 1194 1197 { 1195 1198 struct vchiq_instance *instance = file->private_data; 1196 - struct vchiq_state *state = vchiq_get_state(); 1199 + struct vchiq_state *state = instance->state; 1197 1200 struct vchiq_service *service; 1198 1201 int ret = 0; 1199 1202 int i; ··· 1243 1246 break; 1244 1247 } 1245 1248 1246 - spin_lock(&msg_queue_spinlock); 1249 + spin_lock(&service->state->msg_queue_spinlock); 1247 1250 1248 1251 while (user_service->msg_remove != user_service->msg_insert) { 1249 1252 struct vchiq_header *header; ··· 1251 1254 1252 1255 header = user_service->msg_queue[m]; 1253 1256 user_service->msg_remove++; 1254 - spin_unlock(&msg_queue_spinlock); 1257 + spin_unlock(&service->state->msg_queue_spinlock); 1255 1258 1256 1259 if (header) 1257 1260 vchiq_release_message(instance, service->handle, header); 1258 - spin_lock(&msg_queue_spinlock); 1261 + spin_lock(&service->state->msg_queue_spinlock); 1259 1262 } 1260 1263 1261 - spin_unlock(&msg_queue_spinlock); 1264 + spin_unlock(&service->state->msg_queue_spinlock); 1262 1265 1263 1266 vchiq_service_put(service); 1264 1267 }
+8 -6
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
··· 26 26 #include <media/videobuf2-vmalloc.h> 27 27 28 28 #include "../include/linux/raspberrypi/vchiq.h" 29 + #include "../interface/vchiq_arm/vchiq_arm.h" 29 30 #include "mmal-common.h" 30 31 #include "mmal-vchiq.h" 31 32 #include "mmal-msg.h" ··· 549 548 } 550 549 551 550 /* incoming event service callback */ 552 - static int service_callback(struct vchiq_instance *vchiq_instance, 553 - enum vchiq_reason reason, struct vchiq_header *header, 554 - unsigned int handle, void *bulk_ctx) 551 + static int mmal_service_callback(struct vchiq_instance *vchiq_instance, 552 + enum vchiq_reason reason, struct vchiq_header *header, 553 + unsigned int handle, void *bulk_ctx) 555 554 { 556 555 struct vchiq_mmal_instance *instance = vchiq_get_service_userdata(vchiq_instance, handle); 557 556 u32 msg_len; ··· 1853 1852 } 1854 1853 EXPORT_SYMBOL_GPL(vchiq_mmal_finalise); 1855 1854 1856 - int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance) 1855 + int vchiq_mmal_init(struct device *dev, struct vchiq_mmal_instance **out_instance) 1857 1856 { 1858 1857 int status; 1859 1858 int err = -ENODEV; ··· 1863 1862 .version = VC_MMAL_VER, 1864 1863 .version_min = VC_MMAL_MIN_VER, 1865 1864 .fourcc = VCHIQ_MAKE_FOURCC('m', 'm', 'a', 'l'), 1866 - .callback = service_callback, 1865 + .callback = mmal_service_callback, 1867 1866 .userdata = NULL, 1868 1867 }; 1868 + struct vchiq_drv_mgmt *mgmt = dev_get_drvdata(dev->parent); 1869 1869 1870 1870 /* compile time checks to ensure structure size as they are 1871 1871 * directly (de)serialised from memory. ··· 1882 1880 BUILD_BUG_ON(sizeof(struct mmal_port) != 64); 1883 1881 1884 1882 /* create a vchi instance */ 1885 - status = vchiq_initialise(&vchiq_instance); 1883 + status = vchiq_initialise(&mgmt->state, &vchiq_instance); 1886 1884 if (status) { 1887 1885 pr_err("Failed to initialise VCHI instance (status=%d)\n", 1888 1886 status);
+13 -19
drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
··· 25 25 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128 26 26 27 27 struct vchiq_mmal_instance; 28 + struct device; 28 29 29 30 enum vchiq_mmal_es_type { 30 31 MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */ ··· 43 42 44 43 struct vchiq_mmal_port; 45 44 46 - typedef void (*vchiq_mmal_buffer_cb)( 47 - struct vchiq_mmal_instance *instance, 45 + typedef void (*vchiq_mmal_buffer_cb)(struct vchiq_mmal_instance *instance, 48 46 struct vchiq_mmal_port *port, 49 47 int status, struct mmal_buffer *buffer); 50 48 ··· 95 95 u32 client_component; /* Used to ref back to client struct */ 96 96 }; 97 97 98 - int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance); 98 + int vchiq_mmal_init(struct device *dev, struct vchiq_mmal_instance **out_instance); 99 99 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance); 100 100 101 101 /* Initialise a mmal component and its ports 102 102 * 103 103 */ 104 - int vchiq_mmal_component_init( 105 - struct vchiq_mmal_instance *instance, 106 - const char *name, 107 - struct vchiq_mmal_component **component_out); 104 + int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance, 105 + const char *name, struct vchiq_mmal_component **component_out); 108 106 109 - int vchiq_mmal_component_finalise( 110 - struct vchiq_mmal_instance *instance, 111 - struct vchiq_mmal_component *component); 107 + int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance, 108 + struct vchiq_mmal_component *component); 112 109 113 - int vchiq_mmal_component_enable( 114 - struct vchiq_mmal_instance *instance, 115 - struct vchiq_mmal_component *component); 110 + int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance, 111 + struct vchiq_mmal_component *component); 116 112 117 - int vchiq_mmal_component_disable( 118 - struct vchiq_mmal_instance *instance, 119 - struct vchiq_mmal_component *component); 113 + int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance, 114 + struct vchiq_mmal_component *component); 120 115 121 116 /* enable a mmal port 122 117 * 123 118 * enables a port and if a buffer callback provided enque buffer 124 119 * headers as appropriate for the port. 125 120 */ 126 - int vchiq_mmal_port_enable( 127 - struct vchiq_mmal_instance *instance, 128 - struct vchiq_mmal_port *port, 121 + int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance, 122 + struct vchiq_mmal_port *port, 129 123 vchiq_mmal_buffer_cb buffer_cb); 130 124 131 125 /* disable a port
-4
drivers/staging/vt6655/rf.h
··· 68 68 void RFvRSSITodBm(struct vnt_private *priv, unsigned char byCurrRSSI, 69 69 long *pldBm); 70 70 71 - /* {{ RobertYu: 20050104 */ 72 - bool RFbAL7230SelectChannelPostProcess(struct vnt_private *priv, u16 byOldChannel, u16 byNewChannel); 73 - /* }} RobertYu */ 74 - 75 71 #endif /* __RF_H__ */
-1
drivers/staging/vt6655/srom.c
··· 64 64 unsigned char byData; 65 65 unsigned char byOrg; 66 66 67 - byData = 0xFF; 68 67 byOrg = ioread8(iobase + MAC_REG_I2MCFG); 69 68 /* turn off hardware retry for getting NACK */ 70 69 iowrite8(byOrg & (~I2MCFG_NORETRY), iobase + MAC_REG_I2MCFG);
-13
drivers/staging/wlan-ng/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - config PRISM2_USB 3 - tristate "Prism2.5/3 USB driver" 4 - depends on WLAN && USB && CFG80211 5 - select WIRELESS_EXT 6 - select WEXT_PRIV 7 - select CRC32 8 - help 9 - This is the wlan-ng prism 2.5/3 USB driver for a wide range of 10 - old USB wireless devices. 11 - 12 - To compile this driver as a module, choose M here: the module 13 - will be called prism2_usb.
-8
drivers/staging/wlan-ng/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0 2 - obj-$(CONFIG_PRISM2_USB) += prism2_usb.o 3 - 4 - prism2_usb-y := prism2usb.o \ 5 - p80211conv.o \ 6 - p80211req.o \ 7 - p80211wep.o \ 8 - p80211netdev.o
-8
drivers/staging/wlan-ng/README
··· 1 - TODO: 2 - - checkpatch.pl cleanups 3 - - sparse warnings 4 - - move to use the in-kernel wireless stack 5 - 6 - Please send any patches or complaints about this driver to Greg 7 - Kroah-Hartman <greg@kroah.com> and don't bother the upstream wireless 8 - kernel developers about it, they want nothing to do with it.
-16
drivers/staging/wlan-ng/TODO
··· 1 - To-do list: 2 - 3 - * Correct the coding style according to Linux guidelines; please read the document 4 - at https://www.kernel.org/doc/html/latest/process/coding-style.html. 5 - * Remove unnecessary debugging/printing macros; for those that are still needed 6 - use the proper kernel API (pr_debug(), dev_dbg(), netdev_dbg()). 7 - * Remove dead code such as unusued functions, variables, fields, etc.. 8 - * Use in-kernel API and remove unnecessary wrappers where possible. 9 - * Fix bugs due to code that sleeps in atomic context. 10 - * Remove the HAL layer and migrate its functionality into the relevant parts of 11 - the driver. 12 - * Switch to use LIB80211. 13 - * Switch to use MAC80211. 14 - * Switch to use CFG80211. 15 - * Improve the error handling of various functions, particularly those that use 16 - existing kernel APIs.
-718
drivers/staging/wlan-ng/cfg80211.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* cfg80211 Interface for prism2_usb module */ 3 - #include "hfa384x.h" 4 - #include "prism2mgmt.h" 5 - 6 - /* Prism2 channel/frequency/bitrate declarations */ 7 - static const struct ieee80211_channel prism2_channels[] = { 8 - { .center_freq = 2412 }, 9 - { .center_freq = 2417 }, 10 - { .center_freq = 2422 }, 11 - { .center_freq = 2427 }, 12 - { .center_freq = 2432 }, 13 - { .center_freq = 2437 }, 14 - { .center_freq = 2442 }, 15 - { .center_freq = 2447 }, 16 - { .center_freq = 2452 }, 17 - { .center_freq = 2457 }, 18 - { .center_freq = 2462 }, 19 - { .center_freq = 2467 }, 20 - { .center_freq = 2472 }, 21 - { .center_freq = 2484 }, 22 - }; 23 - 24 - static const struct ieee80211_rate prism2_rates[] = { 25 - { .bitrate = 10 }, 26 - { .bitrate = 20 }, 27 - { .bitrate = 55 }, 28 - { .bitrate = 110 } 29 - }; 30 - 31 - #define PRISM2_NUM_CIPHER_SUITES 2 32 - static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = { 33 - WLAN_CIPHER_SUITE_WEP40, 34 - WLAN_CIPHER_SUITE_WEP104 35 - }; 36 - 37 - /* prism2 device private data */ 38 - struct prism2_wiphy_private { 39 - struct wlandevice *wlandev; 40 - 41 - struct ieee80211_supported_band band; 42 - struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)]; 43 - struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)]; 44 - 45 - struct cfg80211_scan_request *scan_request; 46 - }; 47 - 48 - static const void * const prism2_wiphy_privid = &prism2_wiphy_privid; 49 - 50 - /* Helper Functions */ 51 - static int prism2_result2err(int prism2_result) 52 - { 53 - int err = 0; 54 - 55 - switch (prism2_result) { 56 - case P80211ENUM_resultcode_invalid_parameters: 57 - err = -EINVAL; 58 - break; 59 - case P80211ENUM_resultcode_implementation_failure: 60 - err = -EIO; 61 - break; 62 - case P80211ENUM_resultcode_not_supported: 63 - err = -EOPNOTSUPP; 64 - break; 65 - default: 66 - err = 0; 67 - break; 68 - } 69 - 70 - return err; 71 - } 72 - 73 - static int prism2_domibset_uint32(struct wlandevice *wlandev, 74 - u32 did, u32 data) 75 - { 76 - struct p80211msg_dot11req_mibset msg; 77 - struct p80211item_uint32 *mibitem = 78 - (struct p80211item_uint32 *)&msg.mibattribute.data; 79 - 80 - msg.msgcode = DIDMSG_DOT11REQ_MIBSET; 81 - mibitem->did = did; 82 - mibitem->data = data; 83 - 84 - return p80211req_dorequest(wlandev, (u8 *)&msg); 85 - } 86 - 87 - static int prism2_domibset_pstr32(struct wlandevice *wlandev, 88 - u32 did, u8 len, const u8 *data) 89 - { 90 - struct p80211msg_dot11req_mibset msg; 91 - struct p80211item_pstr32 *mibitem = 92 - (struct p80211item_pstr32 *)&msg.mibattribute.data; 93 - 94 - msg.msgcode = DIDMSG_DOT11REQ_MIBSET; 95 - mibitem->did = did; 96 - mibitem->data.len = len; 97 - memcpy(mibitem->data.data, data, len); 98 - 99 - return p80211req_dorequest(wlandev, (u8 *)&msg); 100 - } 101 - 102 - /* The interface functions, called by the cfg80211 layer */ 103 - static int prism2_change_virtual_intf(struct wiphy *wiphy, 104 - struct net_device *dev, 105 - enum nl80211_iftype type, 106 - struct vif_params *params) 107 - { 108 - struct wlandevice *wlandev = dev->ml_priv; 109 - u32 data; 110 - int result; 111 - int err = 0; 112 - 113 - switch (type) { 114 - case NL80211_IFTYPE_ADHOC: 115 - if (wlandev->macmode == WLAN_MACMODE_IBSS_STA) 116 - goto exit; 117 - wlandev->macmode = WLAN_MACMODE_IBSS_STA; 118 - data = 0; 119 - break; 120 - case NL80211_IFTYPE_STATION: 121 - if (wlandev->macmode == WLAN_MACMODE_ESS_STA) 122 - goto exit; 123 - wlandev->macmode = WLAN_MACMODE_ESS_STA; 124 - data = 1; 125 - break; 126 - default: 127 - netdev_warn(dev, "Operation mode: %d not support\n", type); 128 - return -EOPNOTSUPP; 129 - } 130 - 131 - /* Set Operation mode to the PORT TYPE RID */ 132 - result = prism2_domibset_uint32(wlandev, 133 - DIDMIB_P2_STATIC_CNFPORTTYPE, 134 - data); 135 - 136 - if (result) 137 - err = -EFAULT; 138 - 139 - dev->ieee80211_ptr->iftype = type; 140 - 141 - exit: 142 - return err; 143 - } 144 - 145 - static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev, 146 - int link_id, u8 key_index, bool pairwise, 147 - const u8 *mac_addr, struct key_params *params) 148 - { 149 - struct wlandevice *wlandev = dev->ml_priv; 150 - u32 did; 151 - 152 - if (key_index >= NUM_WEPKEYS) 153 - return -EINVAL; 154 - 155 - if (params->cipher != WLAN_CIPHER_SUITE_WEP40 && 156 - params->cipher != WLAN_CIPHER_SUITE_WEP104) { 157 - pr_debug("Unsupported cipher suite\n"); 158 - return -EFAULT; 159 - } 160 - 161 - if (prism2_domibset_uint32(wlandev, 162 - DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, 163 - key_index)) 164 - return -EFAULT; 165 - 166 - /* send key to driver */ 167 - did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1); 168 - 169 - if (prism2_domibset_pstr32(wlandev, did, params->key_len, params->key)) 170 - return -EFAULT; 171 - return 0; 172 - } 173 - 174 - static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev, 175 - int link_id, u8 key_index, bool pairwise, 176 - const u8 *mac_addr, void *cookie, 177 - void (*callback)(void *cookie, struct key_params*)) 178 - { 179 - struct wlandevice *wlandev = dev->ml_priv; 180 - struct key_params params; 181 - int len; 182 - 183 - if (key_index >= NUM_WEPKEYS) 184 - return -EINVAL; 185 - 186 - len = wlandev->wep_keylens[key_index]; 187 - memset(&params, 0, sizeof(params)); 188 - 189 - if (len == 13) 190 - params.cipher = WLAN_CIPHER_SUITE_WEP104; 191 - else if (len == 5) 192 - params.cipher = WLAN_CIPHER_SUITE_WEP104; 193 - else 194 - return -ENOENT; 195 - params.key_len = len; 196 - params.key = wlandev->wep_keys[key_index]; 197 - params.seq_len = 0; 198 - 199 - callback(cookie, &params); 200 - 201 - return 0; 202 - } 203 - 204 - static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev, 205 - int link_id, u8 key_index, bool pairwise, 206 - const u8 *mac_addr) 207 - { 208 - struct wlandevice *wlandev = dev->ml_priv; 209 - u32 did; 210 - int err = 0; 211 - int result = 0; 212 - 213 - /* There is no direct way in the hardware (AFAIK) of removing 214 - * a key, so we will cheat by setting the key to a bogus value 215 - */ 216 - 217 - if (key_index >= NUM_WEPKEYS) 218 - return -EINVAL; 219 - 220 - /* send key to driver */ 221 - did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1); 222 - result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000"); 223 - 224 - if (result) 225 - err = -EFAULT; 226 - 227 - return err; 228 - } 229 - 230 - static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev, 231 - int link_id, u8 key_index, bool unicast, 232 - bool multicast) 233 - { 234 - struct wlandevice *wlandev = dev->ml_priv; 235 - 236 - return prism2_domibset_uint32(wlandev, 237 - DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, 238 - key_index); 239 - } 240 - 241 - static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev, 242 - const u8 *mac, struct station_info *sinfo) 243 - { 244 - struct wlandevice *wlandev = dev->ml_priv; 245 - struct p80211msg_lnxreq_commsquality quality; 246 - int result; 247 - 248 - memset(sinfo, 0, sizeof(*sinfo)); 249 - 250 - if (!wlandev || (wlandev->msdstate != WLAN_MSD_RUNNING)) 251 - return -EOPNOTSUPP; 252 - 253 - /* build request message */ 254 - quality.msgcode = DIDMSG_LNXREQ_COMMSQUALITY; 255 - quality.dbm.data = P80211ENUM_truth_true; 256 - quality.dbm.status = P80211ENUM_msgitem_status_data_ok; 257 - 258 - /* send message to nsd */ 259 - if (!wlandev->mlmerequest) 260 - return -EOPNOTSUPP; 261 - 262 - result = wlandev->mlmerequest(wlandev, (struct p80211msg *)&quality); 263 - 264 - if (result == 0) { 265 - sinfo->txrate.legacy = quality.txrate.data; 266 - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); 267 - sinfo->signal = quality.level.data; 268 - sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); 269 - } 270 - 271 - return result; 272 - } 273 - 274 - static int prism2_scan(struct wiphy *wiphy, 275 - struct cfg80211_scan_request *request) 276 - { 277 - struct net_device *dev; 278 - struct prism2_wiphy_private *priv = wiphy_priv(wiphy); 279 - struct wlandevice *wlandev; 280 - struct p80211msg_dot11req_scan msg1; 281 - struct p80211msg_dot11req_scan_results *msg2; 282 - struct cfg80211_bss *bss; 283 - struct cfg80211_scan_info info = {}; 284 - 285 - int result; 286 - int err = 0; 287 - int numbss = 0; 288 - int i = 0; 289 - u8 ie_buf[46]; 290 - int ie_len; 291 - 292 - if (!request) 293 - return -EINVAL; 294 - 295 - dev = request->wdev->netdev; 296 - wlandev = dev->ml_priv; 297 - 298 - if (priv->scan_request && priv->scan_request != request) 299 - return -EBUSY; 300 - 301 - if (wlandev->macmode == WLAN_MACMODE_ESS_AP) { 302 - netdev_err(dev, "Can't scan in AP mode\n"); 303 - return -EOPNOTSUPP; 304 - } 305 - 306 - msg2 = kzalloc(sizeof(*msg2), GFP_KERNEL); 307 - if (!msg2) 308 - return -ENOMEM; 309 - 310 - priv->scan_request = request; 311 - 312 - memset(&msg1, 0x00, sizeof(msg1)); 313 - msg1.msgcode = DIDMSG_DOT11REQ_SCAN; 314 - msg1.bsstype.data = P80211ENUM_bsstype_any; 315 - 316 - memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data)); 317 - msg1.bssid.data.len = 6; 318 - 319 - if (request->n_ssids > 0) { 320 - msg1.scantype.data = P80211ENUM_scantype_active; 321 - msg1.ssid.data.len = request->ssids->ssid_len; 322 - memcpy(msg1.ssid.data.data, 323 - request->ssids->ssid, request->ssids->ssid_len); 324 - } else { 325 - msg1.scantype.data = 0; 326 - } 327 - msg1.probedelay.data = 0; 328 - 329 - for (i = 0; 330 - (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels); 331 - i++) 332 - msg1.channellist.data.data[i] = 333 - ieee80211_frequency_to_channel(request->channels[i]->center_freq); 334 - msg1.channellist.data.len = request->n_channels; 335 - 336 - msg1.maxchanneltime.data = 250; 337 - msg1.minchanneltime.data = 200; 338 - 339 - result = p80211req_dorequest(wlandev, (u8 *)&msg1); 340 - if (result) { 341 - err = prism2_result2err(msg1.resultcode.data); 342 - goto exit; 343 - } 344 - /* Now retrieve scan results */ 345 - numbss = msg1.numbss.data; 346 - 347 - for (i = 0; i < numbss; i++) { 348 - int freq; 349 - 350 - msg2->msgcode = DIDMSG_DOT11REQ_SCAN_RESULTS; 351 - msg2->bssindex.data = i; 352 - 353 - result = p80211req_dorequest(wlandev, (u8 *)&msg2); 354 - if ((result != 0) || 355 - (msg2->resultcode.data != P80211ENUM_resultcode_success)) { 356 - break; 357 - } 358 - 359 - ie_buf[0] = WLAN_EID_SSID; 360 - ie_buf[1] = msg2->ssid.data.len; 361 - ie_len = ie_buf[1] + 2; 362 - memcpy(&ie_buf[2], &msg2->ssid.data.data, msg2->ssid.data.len); 363 - freq = ieee80211_channel_to_frequency(msg2->dschannel.data, 364 - NL80211_BAND_2GHZ); 365 - bss = cfg80211_inform_bss(wiphy, 366 - ieee80211_get_channel(wiphy, freq), 367 - CFG80211_BSS_FTYPE_UNKNOWN, 368 - (const u8 *)&msg2->bssid.data.data, 369 - msg2->timestamp.data, msg2->capinfo.data, 370 - msg2->beaconperiod.data, 371 - ie_buf, 372 - ie_len, 373 - (msg2->signal.data - 65536) * 100, /* Conversion to signed type */ 374 - GFP_KERNEL); 375 - 376 - if (!bss) { 377 - err = -ENOMEM; 378 - goto exit; 379 - } 380 - 381 - cfg80211_put_bss(wiphy, bss); 382 - } 383 - 384 - if (result) 385 - err = prism2_result2err(msg2->resultcode.data); 386 - 387 - exit: 388 - info.aborted = !!(err); 389 - cfg80211_scan_done(request, &info); 390 - priv->scan_request = NULL; 391 - kfree(msg2); 392 - return err; 393 - } 394 - 395 - static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed) 396 - { 397 - struct prism2_wiphy_private *priv = wiphy_priv(wiphy); 398 - struct wlandevice *wlandev = priv->wlandev; 399 - u32 data; 400 - int result; 401 - int err = 0; 402 - 403 - if (changed & WIPHY_PARAM_RTS_THRESHOLD) { 404 - if (wiphy->rts_threshold == -1) 405 - data = 2347; 406 - else 407 - data = wiphy->rts_threshold; 408 - 409 - result = prism2_domibset_uint32(wlandev, 410 - DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD, 411 - data); 412 - if (result) { 413 - err = -EFAULT; 414 - goto exit; 415 - } 416 - } 417 - 418 - if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { 419 - if (wiphy->frag_threshold == -1) 420 - data = 2346; 421 - else 422 - data = wiphy->frag_threshold; 423 - 424 - result = prism2_domibset_uint32(wlandev, 425 - DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD, 426 - data); 427 - if (result) { 428 - err = -EFAULT; 429 - goto exit; 430 - } 431 - } 432 - 433 - exit: 434 - return err; 435 - } 436 - 437 - static int prism2_connect(struct wiphy *wiphy, struct net_device *dev, 438 - struct cfg80211_connect_params *sme) 439 - { 440 - struct wlandevice *wlandev = dev->ml_priv; 441 - struct ieee80211_channel *channel = sme->channel; 442 - struct p80211msg_lnxreq_autojoin msg_join; 443 - u32 did; 444 - int length = sme->ssid_len; 445 - int chan = -1; 446 - int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) || 447 - (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104); 448 - int result; 449 - int err = 0; 450 - 451 - /* Set the channel */ 452 - if (channel) { 453 - chan = ieee80211_frequency_to_channel(channel->center_freq); 454 - result = prism2_domibset_uint32(wlandev, 455 - DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL, 456 - chan); 457 - if (result) 458 - goto exit; 459 - } 460 - 461 - /* Set the authorization */ 462 - if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) || 463 - ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep)) 464 - msg_join.authtype.data = P80211ENUM_authalg_opensystem; 465 - else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) || 466 - ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep)) 467 - msg_join.authtype.data = P80211ENUM_authalg_sharedkey; 468 - else 469 - netdev_warn(dev, 470 - "Unhandled authorisation type for connect (%d)\n", 471 - sme->auth_type); 472 - 473 - /* Set the encryption - we only support wep */ 474 - if (is_wep) { 475 - if (sme->key) { 476 - if (sme->key_idx >= NUM_WEPKEYS) 477 - return -EINVAL; 478 - 479 - result = prism2_domibset_uint32(wlandev, 480 - DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, 481 - sme->key_idx); 482 - if (result) 483 - goto exit; 484 - 485 - /* send key to driver */ 486 - did = didmib_dot11smt_wepdefaultkeystable_key(sme->key_idx + 1); 487 - result = prism2_domibset_pstr32(wlandev, 488 - did, sme->key_len, 489 - (u8 *)sme->key); 490 - if (result) 491 - goto exit; 492 - } 493 - 494 - /* Assume we should set privacy invoked and exclude unencrypted 495 - * We could possible use sme->privacy here, but the assumption 496 - * seems reasonable anyways 497 - */ 498 - result = prism2_domibset_uint32(wlandev, 499 - DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED, 500 - P80211ENUM_truth_true); 501 - if (result) 502 - goto exit; 503 - 504 - result = prism2_domibset_uint32(wlandev, 505 - DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED, 506 - P80211ENUM_truth_true); 507 - if (result) 508 - goto exit; 509 - 510 - } else { 511 - /* Assume we should unset privacy invoked 512 - * and exclude unencrypted 513 - */ 514 - result = prism2_domibset_uint32(wlandev, 515 - DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED, 516 - P80211ENUM_truth_false); 517 - if (result) 518 - goto exit; 519 - 520 - result = prism2_domibset_uint32(wlandev, 521 - DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED, 522 - P80211ENUM_truth_false); 523 - if (result) 524 - goto exit; 525 - } 526 - 527 - /* Now do the actual join. Note there is no way that I can 528 - * see to request a specific bssid 529 - */ 530 - msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN; 531 - 532 - memcpy(msg_join.ssid.data.data, sme->ssid, length); 533 - msg_join.ssid.data.len = length; 534 - 535 - result = p80211req_dorequest(wlandev, (u8 *)&msg_join); 536 - 537 - exit: 538 - if (result) 539 - err = -EFAULT; 540 - 541 - return err; 542 - } 543 - 544 - static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev, 545 - u16 reason_code) 546 - { 547 - struct wlandevice *wlandev = dev->ml_priv; 548 - struct p80211msg_lnxreq_autojoin msg_join; 549 - int result; 550 - int err = 0; 551 - 552 - /* Do a join, with a bogus ssid. Thats the only way I can think of */ 553 - msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN; 554 - 555 - memcpy(msg_join.ssid.data.data, "---", 3); 556 - msg_join.ssid.data.len = 3; 557 - 558 - result = p80211req_dorequest(wlandev, (u8 *)&msg_join); 559 - 560 - if (result) 561 - err = -EFAULT; 562 - 563 - return err; 564 - } 565 - 566 - static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev, 567 - struct cfg80211_ibss_params *params) 568 - { 569 - return -EOPNOTSUPP; 570 - } 571 - 572 - static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev) 573 - { 574 - return -EOPNOTSUPP; 575 - } 576 - 577 - static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, 578 - enum nl80211_tx_power_setting type, int mbm) 579 - { 580 - struct prism2_wiphy_private *priv = wiphy_priv(wiphy); 581 - struct wlandevice *wlandev = priv->wlandev; 582 - u32 data; 583 - int result; 584 - int err = 0; 585 - 586 - if (type == NL80211_TX_POWER_AUTOMATIC) 587 - data = 30; 588 - else 589 - data = MBM_TO_DBM(mbm); 590 - 591 - result = prism2_domibset_uint32(wlandev, 592 - DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL, 593 - data); 594 - 595 - if (result) { 596 - err = -EFAULT; 597 - goto exit; 598 - } 599 - 600 - exit: 601 - return err; 602 - } 603 - 604 - static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, 605 - int *dbm) 606 - { 607 - struct prism2_wiphy_private *priv = wiphy_priv(wiphy); 608 - struct wlandevice *wlandev = priv->wlandev; 609 - struct p80211msg_dot11req_mibget msg; 610 - struct p80211item_uint32 *mibitem; 611 - int result; 612 - int err = 0; 613 - 614 - mibitem = (struct p80211item_uint32 *)&msg.mibattribute.data; 615 - msg.msgcode = DIDMSG_DOT11REQ_MIBGET; 616 - mibitem->did = DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL; 617 - 618 - result = p80211req_dorequest(wlandev, (u8 *)&msg); 619 - 620 - if (result) { 621 - err = -EFAULT; 622 - goto exit; 623 - } 624 - 625 - *dbm = mibitem->data; 626 - 627 - exit: 628 - return err; 629 - } 630 - 631 - /* Interface callback functions, passing data back up to the cfg80211 layer */ 632 - void prism2_connect_result(struct wlandevice *wlandev, u8 failed) 633 - { 634 - u16 status = failed ? 635 - WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS; 636 - 637 - cfg80211_connect_result(wlandev->netdev, wlandev->bssid, 638 - NULL, 0, NULL, 0, status, GFP_KERNEL); 639 - } 640 - 641 - void prism2_disconnected(struct wlandevice *wlandev) 642 - { 643 - cfg80211_disconnected(wlandev->netdev, 0, NULL, 644 - 0, false, GFP_KERNEL); 645 - } 646 - 647 - void prism2_roamed(struct wlandevice *wlandev) 648 - { 649 - struct cfg80211_roam_info roam_info = { 650 - .links[0].bssid = wlandev->bssid, 651 - }; 652 - 653 - cfg80211_roamed(wlandev->netdev, &roam_info, GFP_KERNEL); 654 - } 655 - 656 - /* Structures for declaring wiphy interface */ 657 - static const struct cfg80211_ops prism2_usb_cfg_ops = { 658 - .change_virtual_intf = prism2_change_virtual_intf, 659 - .add_key = prism2_add_key, 660 - .get_key = prism2_get_key, 661 - .del_key = prism2_del_key, 662 - .set_default_key = prism2_set_default_key, 663 - .get_station = prism2_get_station, 664 - .scan = prism2_scan, 665 - .set_wiphy_params = prism2_set_wiphy_params, 666 - .connect = prism2_connect, 667 - .disconnect = prism2_disconnect, 668 - .join_ibss = prism2_join_ibss, 669 - .leave_ibss = prism2_leave_ibss, 670 - .set_tx_power = prism2_set_tx_power, 671 - .get_tx_power = prism2_get_tx_power, 672 - }; 673 - 674 - /* Functions to create/free wiphy interface */ 675 - static struct wiphy *wlan_create_wiphy(struct device *dev, 676 - struct wlandevice *wlandev) 677 - { 678 - struct wiphy *wiphy; 679 - struct prism2_wiphy_private *priv; 680 - 681 - wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv)); 682 - if (!wiphy) 683 - return NULL; 684 - 685 - priv = wiphy_priv(wiphy); 686 - priv->wlandev = wlandev; 687 - memcpy(priv->channels, prism2_channels, sizeof(prism2_channels)); 688 - memcpy(priv->rates, prism2_rates, sizeof(prism2_rates)); 689 - priv->band.channels = priv->channels; 690 - priv->band.n_channels = ARRAY_SIZE(prism2_channels); 691 - priv->band.bitrates = priv->rates; 692 - priv->band.n_bitrates = ARRAY_SIZE(prism2_rates); 693 - priv->band.band = NL80211_BAND_2GHZ; 694 - priv->band.ht_cap.ht_supported = false; 695 - wiphy->bands[NL80211_BAND_2GHZ] = &priv->band; 696 - 697 - set_wiphy_dev(wiphy, dev); 698 - wiphy->privid = prism2_wiphy_privid; 699 - wiphy->max_scan_ssids = 1; 700 - wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) 701 - | BIT(NL80211_IFTYPE_ADHOC); 702 - wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; 703 - wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES; 704 - wiphy->cipher_suites = prism2_cipher_suites; 705 - 706 - if (wiphy_register(wiphy) < 0) { 707 - wiphy_free(wiphy); 708 - return NULL; 709 - } 710 - 711 - return wiphy; 712 - } 713 - 714 - static void wlan_free_wiphy(struct wiphy *wiphy) 715 - { 716 - wiphy_unregister(wiphy); 717 - wiphy_free(wiphy); 718 - }
-1236
drivers/staging/wlan-ng/hfa384x.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Defines the constants and data structures for the hfa384x 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * [Implementation and usage notes] 28 - * 29 - * [References] 30 - * CW10 Programmer's Manual v1.5 31 - * IEEE 802.11 D10.0 32 - * 33 - * -------------------------------------------------------------------- 34 - */ 35 - 36 - #ifndef _HFA384x_H 37 - #define _HFA384x_H 38 - 39 - #define HFA384x_FIRMWARE_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) 40 - 41 - #include <linux/if_ether.h> 42 - #include <linux/usb.h> 43 - 44 - /*--- Mins & Maxs -----------------------------------*/ 45 - #define HFA384x_PORTID_MAX ((u16)7) 46 - #define HFA384x_NUMPORTS_MAX ((u16)(HFA384x_PORTID_MAX + 1)) 47 - #define HFA384x_PDR_LEN_MAX ((u16)512) /* in bytes, from EK */ 48 - #define HFA384x_PDA_RECS_MAX ((u16)200) /* a guess */ 49 - #define HFA384x_PDA_LEN_MAX ((u16)1024) /* in bytes, from EK*/ 50 - #define HFA384x_SCANRESULT_MAX ((u16)31) 51 - #define HFA384x_HSCANRESULT_MAX ((u16)31) 52 - #define HFA384x_CHINFORESULT_MAX ((u16)16) 53 - #define HFA384x_RID_GUESSING_MAXLEN 2048 /* I'm not really sure */ 54 - #define HFA384x_RIDDATA_MAXLEN HFA384x_RID_GUESSING_MAXLEN 55 - #define HFA384x_USB_RWMEM_MAXLEN 2048 56 - 57 - /*--- Support Constants -----------------------------*/ 58 - #define HFA384x_PORTTYPE_IBSS ((u16)0) 59 - #define HFA384x_PORTTYPE_BSS ((u16)1) 60 - #define HFA384x_PORTTYPE_PSUEDOIBSS ((u16)3) 61 - #define HFA384x_WEPFLAGS_PRIVINVOKED ((u16)BIT(0)) 62 - #define HFA384x_WEPFLAGS_EXCLUDE ((u16)BIT(1)) 63 - #define HFA384x_WEPFLAGS_DISABLE_TXCRYPT ((u16)BIT(4)) 64 - #define HFA384x_WEPFLAGS_DISABLE_RXCRYPT ((u16)BIT(7)) 65 - #define HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM ((u16)3) 66 - #define HFA384x_PORTSTATUS_DISABLED ((u16)1) 67 - #define HFA384x_RATEBIT_1 ((u16)1) 68 - #define HFA384x_RATEBIT_2 ((u16)2) 69 - #define HFA384x_RATEBIT_5dot5 ((u16)4) 70 - #define HFA384x_RATEBIT_11 ((u16)8) 71 - 72 - /*--- MAC Internal memory constants and macros ------*/ 73 - /* masks and macros used to manipulate MAC internal memory addresses. */ 74 - /* MAC internal memory addresses are 23 bit quantities. The MAC uses 75 - * a paged address space where the upper 16 bits are the page number 76 - * and the lower 7 bits are the offset. There are various Host API 77 - * elements that require two 16-bit quantities to specify a MAC 78 - * internal memory address. Unfortunately, some of the API's use a 79 - * page/offset format where the offset value is JUST the lower seven 80 - * bits and the page is the remaining 16 bits. Some of the API's 81 - * assume that the 23 bit address has been split at the 16th bit. We 82 - * refer to these two formats as AUX format and CMD format. The 83 - * macros below help handle some of this. 84 - */ 85 - 86 - /* Mask bits for discarding unwanted pieces in a flat address */ 87 - #define HFA384x_ADDR_FLAT_AUX_PAGE_MASK (0x007fff80) 88 - #define HFA384x_ADDR_FLAT_AUX_OFF_MASK (0x0000007f) 89 - #define HFA384x_ADDR_FLAT_CMD_PAGE_MASK (0xffff0000) 90 - #define HFA384x_ADDR_FLAT_CMD_OFF_MASK (0x0000ffff) 91 - 92 - /* Mask bits for discarding unwanted pieces in AUX format 93 - * 16-bit address parts 94 - */ 95 - #define HFA384x_ADDR_AUX_PAGE_MASK (0xffff) 96 - #define HFA384x_ADDR_AUX_OFF_MASK (0x007f) 97 - 98 - /* Make a 32-bit flat address from AUX format 16-bit page and offset */ 99 - #define HFA384x_ADDR_AUX_MKFLAT(p, o) \ 100 - ((((u32)(((u16)(p)) & HFA384x_ADDR_AUX_PAGE_MASK)) << 7) | \ 101 - ((u32)(((u16)(o)) & HFA384x_ADDR_AUX_OFF_MASK))) 102 - 103 - /* Make CMD format offset and page from a 32-bit flat address */ 104 - #define HFA384x_ADDR_CMD_MKPAGE(f) \ 105 - ((u16)((((u32)(f)) & HFA384x_ADDR_FLAT_CMD_PAGE_MASK) >> 16)) 106 - #define HFA384x_ADDR_CMD_MKOFF(f) \ 107 - ((u16)(((u32)(f)) & HFA384x_ADDR_FLAT_CMD_OFF_MASK)) 108 - 109 - /*--- Controller Memory addresses -------------------*/ 110 - #define HFA3842_PDA_BASE (0x007f0000UL) 111 - #define HFA3841_PDA_BASE (0x003f0000UL) 112 - #define HFA3841_PDA_BOGUS_BASE (0x00390000UL) 113 - 114 - /*--- Driver Download states -----------------------*/ 115 - #define HFA384x_DLSTATE_DISABLED 0 116 - #define HFA384x_DLSTATE_RAMENABLED 1 117 - #define HFA384x_DLSTATE_FLASHENABLED 2 118 - 119 - /*--- Register Field Masks --------------------------*/ 120 - #define HFA384x_CMD_AINFO ((u16)GENMASK(14, 8)) 121 - #define HFA384x_CMD_MACPORT ((u16)GENMASK(10, 8)) 122 - #define HFA384x_CMD_PROGMODE ((u16)GENMASK(9, 8)) 123 - #define HFA384x_CMD_CMDCODE ((u16)GENMASK(5, 0)) 124 - #define HFA384x_STATUS_RESULT ((u16)GENMASK(14, 8)) 125 - 126 - /*--- Command Code Constants --------------------------*/ 127 - /*--- Controller Commands --------------------------*/ 128 - #define HFA384x_CMDCODE_INIT ((u16)0x00) 129 - #define HFA384x_CMDCODE_ENABLE ((u16)0x01) 130 - #define HFA384x_CMDCODE_DISABLE ((u16)0x02) 131 - 132 - /*--- Regulate Commands --------------------------*/ 133 - #define HFA384x_CMDCODE_INQ ((u16)0x11) 134 - 135 - /*--- Configure Commands --------------------------*/ 136 - #define HFA384x_CMDCODE_DOWNLD ((u16)0x22) 137 - 138 - /*--- Debugging Commands -----------------------------*/ 139 - #define HFA384x_CMDCODE_MONITOR ((u16)(0x38)) 140 - #define HFA384x_MONITOR_ENABLE ((u16)(0x0b)) 141 - #define HFA384x_MONITOR_DISABLE ((u16)(0x0f)) 142 - 143 - /*--- Result Codes --------------------------*/ 144 - #define HFA384x_CMD_ERR ((u16)(0x7F)) 145 - 146 - /*--- Programming Modes -------------------------- 147 - * MODE 0: Disable programming 148 - * MODE 1: Enable volatile memory programming 149 - * MODE 2: Enable non-volatile memory programming 150 - * MODE 3: Program non-volatile memory section 151 - *------------------------------------------------- 152 - */ 153 - #define HFA384x_PROGMODE_DISABLE ((u16)0x00) 154 - #define HFA384x_PROGMODE_RAM ((u16)0x01) 155 - #define HFA384x_PROGMODE_NV ((u16)0x02) 156 - #define HFA384x_PROGMODE_NVWRITE ((u16)0x03) 157 - 158 - /*--- Record ID Constants --------------------------*/ 159 - /*-------------------------------------------------------------------- 160 - * Configuration RIDs: Network Parameters, Static Configuration Entities 161 - *-------------------------------------------------------------------- 162 - */ 163 - #define HFA384x_RID_CNFPORTTYPE ((u16)0xFC00) 164 - #define HFA384x_RID_CNFOWNMACADDR ((u16)0xFC01) 165 - #define HFA384x_RID_CNFDESIREDSSID ((u16)0xFC02) 166 - #define HFA384x_RID_CNFOWNCHANNEL ((u16)0xFC03) 167 - #define HFA384x_RID_CNFOWNSSID ((u16)0xFC04) 168 - #define HFA384x_RID_CNFMAXDATALEN ((u16)0xFC07) 169 - 170 - /*-------------------------------------------------------------------- 171 - * Configuration RID lengths: Network Params, Static Config Entities 172 - * This is the length of JUST the DATA part of the RID (does not 173 - * include the len or code fields) 174 - *-------------------------------------------------------------------- 175 - */ 176 - #define HFA384x_RID_CNFOWNMACADDR_LEN ((u16)6) 177 - #define HFA384x_RID_CNFDESIREDSSID_LEN ((u16)34) 178 - #define HFA384x_RID_CNFOWNSSID_LEN ((u16)34) 179 - 180 - /*-------------------------------------------------------------------- 181 - * Configuration RIDs: Network Parameters, Dynamic Configuration Entities 182 - *-------------------------------------------------------------------- 183 - */ 184 - #define HFA384x_RID_CREATEIBSS ((u16)0xFC81) 185 - #define HFA384x_RID_FRAGTHRESH ((u16)0xFC82) 186 - #define HFA384x_RID_RTSTHRESH ((u16)0xFC83) 187 - #define HFA384x_RID_TXRATECNTL ((u16)0xFC84) 188 - #define HFA384x_RID_PROMISCMODE ((u16)0xFC85) 189 - 190 - /*---------------------------------------------------------------------- 191 - * Information RIDs: NIC Information 192 - *---------------------------------------------------------------------- 193 - */ 194 - #define HFA384x_RID_MAXLOADTIME ((u16)0xFD00) 195 - #define HFA384x_RID_DOWNLOADBUFFER ((u16)0xFD01) 196 - #define HFA384x_RID_PRIIDENTITY ((u16)0xFD02) 197 - #define HFA384x_RID_PRISUPRANGE ((u16)0xFD03) 198 - #define HFA384x_RID_PRI_CFIACTRANGES ((u16)0xFD04) 199 - #define HFA384x_RID_NICSERIALNUMBER ((u16)0xFD0A) 200 - #define HFA384x_RID_NICIDENTITY ((u16)0xFD0B) 201 - #define HFA384x_RID_MFISUPRANGE ((u16)0xFD0C) 202 - #define HFA384x_RID_CFISUPRANGE ((u16)0xFD0D) 203 - #define HFA384x_RID_STAIDENTITY ((u16)0xFD20) 204 - #define HFA384x_RID_STASUPRANGE ((u16)0xFD21) 205 - #define HFA384x_RID_STA_MFIACTRANGES ((u16)0xFD22) 206 - #define HFA384x_RID_STA_CFIACTRANGES ((u16)0xFD23) 207 - 208 - /*---------------------------------------------------------------------- 209 - * Information RID Lengths: NIC Information 210 - * This is the length of JUST the DATA part of the RID (does not 211 - * include the len or code fields) 212 - *--------------------------------------------------------------------- 213 - */ 214 - #define HFA384x_RID_NICSERIALNUMBER_LEN ((u16)12) 215 - 216 - /*-------------------------------------------------------------------- 217 - * Information RIDs: MAC Information 218 - *-------------------------------------------------------------------- 219 - */ 220 - #define HFA384x_RID_PORTSTATUS ((u16)0xFD40) 221 - #define HFA384x_RID_CURRENTSSID ((u16)0xFD41) 222 - #define HFA384x_RID_CURRENTBSSID ((u16)0xFD42) 223 - #define HFA384x_RID_CURRENTTXRATE ((u16)0xFD44) 224 - #define HFA384x_RID_SHORTRETRYLIMIT ((u16)0xFD48) 225 - #define HFA384x_RID_LONGRETRYLIMIT ((u16)0xFD49) 226 - #define HFA384x_RID_MAXTXLIFETIME ((u16)0xFD4A) 227 - #define HFA384x_RID_PRIVACYOPTIMP ((u16)0xFD4F) 228 - #define HFA384x_RID_DBMCOMMSQUALITY ((u16)0xFD51) 229 - 230 - /*-------------------------------------------------------------------- 231 - * Information RID Lengths: MAC Information 232 - * This is the length of JUST the DATA part of the RID (does not 233 - * include the len or code fields) 234 - *-------------------------------------------------------------------- 235 - */ 236 - #define HFA384x_RID_DBMCOMMSQUALITY_LEN \ 237 - ((u16)sizeof(struct hfa384x_dbmcommsquality)) 238 - #define HFA384x_RID_JOINREQUEST_LEN \ 239 - ((u16)sizeof(struct hfa384x_join_request_data)) 240 - 241 - /*-------------------------------------------------------------------- 242 - * Information RIDs: Modem Information 243 - *-------------------------------------------------------------------- 244 - */ 245 - #define HFA384x_RID_CURRENTCHANNEL ((u16)0xFDC1) 246 - 247 - /*-------------------------------------------------------------------- 248 - * API ENHANCEMENTS (NOT ALREADY IMPLEMENTED) 249 - *-------------------------------------------------------------------- 250 - */ 251 - #define HFA384x_RID_CNFWEPDEFAULTKEYID ((u16)0xFC23) 252 - #define HFA384x_RID_CNFWEPDEFAULTKEY0 ((u16)0xFC24) 253 - #define HFA384x_RID_CNFWEPDEFAULTKEY1 ((u16)0xFC25) 254 - #define HFA384x_RID_CNFWEPDEFAULTKEY2 ((u16)0xFC26) 255 - #define HFA384x_RID_CNFWEPDEFAULTKEY3 ((u16)0xFC27) 256 - #define HFA384x_RID_CNFWEPFLAGS ((u16)0xFC28) 257 - #define HFA384x_RID_CNFAUTHENTICATION ((u16)0xFC2A) 258 - #define HFA384x_RID_CNFROAMINGMODE ((u16)0xFC2D) 259 - #define HFA384x_RID_CNFAPBCNINT ((u16)0xFC33) 260 - #define HFA384x_RID_CNFDBMADJUST ((u16)0xFC46) 261 - #define HFA384x_RID_CNFWPADATA ((u16)0xFC48) 262 - #define HFA384x_RID_CNFBASICRATES ((u16)0xFCB3) 263 - #define HFA384x_RID_CNFSUPPRATES ((u16)0xFCB4) 264 - #define HFA384x_RID_CNFPASSIVESCANCTRL ((u16)0xFCBA) 265 - #define HFA384x_RID_TXPOWERMAX ((u16)0xFCBE) 266 - #define HFA384x_RID_JOINREQUEST ((u16)0xFCE2) 267 - #define HFA384x_RID_AUTHENTICATESTA ((u16)0xFCE3) 268 - #define HFA384x_RID_HOSTSCAN ((u16)0xFCE5) 269 - 270 - #define HFA384x_RID_CNFWEPDEFAULTKEY_LEN ((u16)6) 271 - #define HFA384x_RID_CNFWEP128DEFAULTKEY_LEN ((u16)14) 272 - 273 - /*-------------------------------------------------------------------- 274 - * PD Record codes 275 - *-------------------------------------------------------------------- 276 - */ 277 - #define HFA384x_PDR_PCB_PARTNUM ((u16)0x0001) 278 - #define HFA384x_PDR_PDAVER ((u16)0x0002) 279 - #define HFA384x_PDR_NIC_SERIAL ((u16)0x0003) 280 - #define HFA384x_PDR_MKK_MEASUREMENTS ((u16)0x0004) 281 - #define HFA384x_PDR_NIC_RAMSIZE ((u16)0x0005) 282 - #define HFA384x_PDR_MFISUPRANGE ((u16)0x0006) 283 - #define HFA384x_PDR_CFISUPRANGE ((u16)0x0007) 284 - #define HFA384x_PDR_NICID ((u16)0x0008) 285 - #define HFA384x_PDR_MAC_ADDRESS ((u16)0x0101) 286 - #define HFA384x_PDR_REGDOMAIN ((u16)0x0103) 287 - #define HFA384x_PDR_ALLOWED_CHANNEL ((u16)0x0104) 288 - #define HFA384x_PDR_DEFAULT_CHANNEL ((u16)0x0105) 289 - #define HFA384x_PDR_TEMPTYPE ((u16)0x0107) 290 - #define HFA384x_PDR_IFR_SETTING ((u16)0x0200) 291 - #define HFA384x_PDR_RFR_SETTING ((u16)0x0201) 292 - #define HFA384x_PDR_HFA3861_BASELINE ((u16)0x0202) 293 - #define HFA384x_PDR_HFA3861_SHADOW ((u16)0x0203) 294 - #define HFA384x_PDR_HFA3861_IFRF ((u16)0x0204) 295 - #define HFA384x_PDR_HFA3861_CHCALSP ((u16)0x0300) 296 - #define HFA384x_PDR_HFA3861_CHCALI ((u16)0x0301) 297 - #define HFA384x_PDR_MAX_TX_POWER ((u16)0x0302) 298 - #define HFA384x_PDR_MASTER_CHAN_LIST ((u16)0x0303) 299 - #define HFA384x_PDR_3842_NIC_CONFIG ((u16)0x0400) 300 - #define HFA384x_PDR_USB_ID ((u16)0x0401) 301 - #define HFA384x_PDR_PCI_ID ((u16)0x0402) 302 - #define HFA384x_PDR_PCI_IFCONF ((u16)0x0403) 303 - #define HFA384x_PDR_PCI_PMCONF ((u16)0x0404) 304 - #define HFA384x_PDR_RFENRGY ((u16)0x0406) 305 - #define HFA384x_PDR_USB_POWER_TYPE ((u16)0x0407) 306 - #define HFA384x_PDR_USB_MAX_POWER ((u16)0x0409) 307 - #define HFA384x_PDR_USB_MANUFACTURER ((u16)0x0410) 308 - #define HFA384x_PDR_USB_PRODUCT ((u16)0x0411) 309 - #define HFA384x_PDR_ANT_DIVERSITY ((u16)0x0412) 310 - #define HFA384x_PDR_HFO_DELAY ((u16)0x0413) 311 - #define HFA384x_PDR_SCALE_THRESH ((u16)0x0414) 312 - 313 - #define HFA384x_PDR_HFA3861_MANF_TESTSP ((u16)0x0900) 314 - #define HFA384x_PDR_HFA3861_MANF_TESTI ((u16)0x0901) 315 - #define HFA384x_PDR_END_OF_PDA ((u16)0x0000) 316 - 317 - /*--- Register Test/Get/Set Field macros ------------------------*/ 318 - 319 - #define HFA384x_CMD_AINFO_SET(value) ((u16)((u16)(value) << 8)) 320 - #define HFA384x_CMD_MACPORT_SET(value) \ 321 - ((u16)HFA384x_CMD_AINFO_SET(value)) 322 - #define HFA384x_CMD_PROGMODE_SET(value) \ 323 - ((u16)HFA384x_CMD_AINFO_SET((u16)value)) 324 - #define HFA384x_CMD_CMDCODE_SET(value) ((u16)(value)) 325 - 326 - #define HFA384x_STATUS_RESULT_SET(value) (((u16)(value)) << 8) 327 - 328 - /* Host Maintained State Info */ 329 - #define HFA384x_STATE_PREINIT 0 330 - #define HFA384x_STATE_INIT 1 331 - #define HFA384x_STATE_RUNNING 2 332 - 333 - /*-------------------------------------------------------------*/ 334 - /* Commonly used basic types */ 335 - struct hfa384x_bytestr { 336 - __le16 len; 337 - u8 data[]; 338 - } __packed; 339 - 340 - struct hfa384x_bytestr32 { 341 - __le16 len; 342 - u8 data[32]; 343 - } __packed; 344 - 345 - /*-------------------------------------------------------------------- 346 - * Configuration Record Structures: 347 - * Network Parameters, Static Configuration Entities 348 - *-------------------------------------------------------------------- 349 - */ 350 - 351 - /*-- Hardware/Firmware Component Information ----------*/ 352 - struct hfa384x_compident { 353 - u16 id; 354 - u16 variant; 355 - u16 major; 356 - u16 minor; 357 - } __packed; 358 - 359 - struct hfa384x_caplevel { 360 - u16 role; 361 - u16 id; 362 - u16 variant; 363 - u16 bottom; 364 - u16 top; 365 - } __packed; 366 - 367 - /*-- Configuration Record: cnfAuthentication --*/ 368 - #define HFA384x_CNFAUTHENTICATION_OPENSYSTEM 0x0001 369 - #define HFA384x_CNFAUTHENTICATION_SHAREDKEY 0x0002 370 - #define HFA384x_CNFAUTHENTICATION_LEAP 0x0004 371 - 372 - /*-------------------------------------------------------------------- 373 - * Configuration Record Structures: 374 - * Network Parameters, Dynamic Configuration Entities 375 - *-------------------------------------------------------------------- 376 - */ 377 - 378 - #define HFA384x_CREATEIBSS_JOINCREATEIBSS 0 379 - 380 - /*-- Configuration Record: HostScanRequest (data portion only) --*/ 381 - struct hfa384x_host_scan_request_data { 382 - __le16 channel_list; 383 - __le16 tx_rate; 384 - struct hfa384x_bytestr32 ssid; 385 - } __packed; 386 - 387 - /*-- Configuration Record: JoinRequest (data portion only) --*/ 388 - struct hfa384x_join_request_data { 389 - u8 bssid[WLAN_BSSID_LEN]; 390 - u16 channel; 391 - } __packed; 392 - 393 - /*-- Configuration Record: authenticateStation (data portion only) --*/ 394 - struct hfa384x_authenticate_station_data { 395 - u8 address[ETH_ALEN]; 396 - __le16 status; 397 - __le16 algorithm; 398 - } __packed; 399 - 400 - /*-- Configuration Record: WPAData (data portion only) --*/ 401 - struct hfa384x_wpa_data { 402 - __le16 datalen; 403 - u8 data[]; /* max 80 */ 404 - } __packed; 405 - 406 - /*-------------------------------------------------------------------- 407 - * Information Record Structures: NIC Information 408 - *-------------------------------------------------------------------- 409 - */ 410 - 411 - /*-- Information Record: DownLoadBuffer --*/ 412 - /* NOTE: The page and offset are in AUX format */ 413 - struct hfa384x_downloadbuffer { 414 - u16 page; 415 - u16 offset; 416 - u16 len; 417 - } __packed; 418 - 419 - /*-------------------------------------------------------------------- 420 - * Information Record Structures: NIC Information 421 - *-------------------------------------------------------------------- 422 - */ 423 - 424 - #define HFA384x_PSTATUS_CONN_IBSS ((u16)3) 425 - 426 - /*-- Information Record: commsquality --*/ 427 - struct hfa384x_commsquality { 428 - __le16 cq_curr_bss; 429 - __le16 asl_curr_bss; 430 - __le16 anl_curr_fc; 431 - } __packed; 432 - 433 - /*-- Information Record: dmbcommsquality --*/ 434 - struct hfa384x_dbmcommsquality { 435 - u16 cq_dbm_curr_bss; 436 - u16 asl_dbm_curr_bss; 437 - u16 anl_dbm_curr_fc; 438 - } __packed; 439 - 440 - /*-------------------------------------------------------------------- 441 - * FRAME STRUCTURES: Communication Frames 442 - *-------------------------------------------------------------------- 443 - * Communication Frames: Transmit Frames 444 - *-------------------------------------------------------------------- 445 - */ 446 - /*-- Communication Frame: Transmit Frame Structure --*/ 447 - struct hfa384x_tx_frame { 448 - u16 status; 449 - u16 reserved1; 450 - u16 reserved2; 451 - u32 sw_support; 452 - u8 tx_retrycount; 453 - u8 tx_rate; 454 - u16 tx_control; 455 - 456 - /*-- 802.11 Header Information --*/ 457 - struct p80211_hdr hdr; 458 - __le16 data_len; /* little endian format */ 459 - 460 - /*-- 802.3 Header Information --*/ 461 - 462 - u8 dest_addr[6]; 463 - u8 src_addr[6]; 464 - u16 data_length; /* big endian format */ 465 - } __packed; 466 - /*-------------------------------------------------------------------- 467 - * Communication Frames: Field Masks for Transmit Frames 468 - *-------------------------------------------------------------------- 469 - */ 470 - /*-- Status Field --*/ 471 - #define HFA384x_TXSTATUS_ACKERR ((u16)BIT(5)) 472 - #define HFA384x_TXSTATUS_FORMERR ((u16)BIT(3)) 473 - #define HFA384x_TXSTATUS_DISCON ((u16)BIT(2)) 474 - #define HFA384x_TXSTATUS_AGEDERR ((u16)BIT(1)) 475 - #define HFA384x_TXSTATUS_RETRYERR ((u16)BIT(0)) 476 - /*-- Transmit Control Field --*/ 477 - #define HFA384x_TX_MACPORT ((u16)GENMASK(10, 8)) 478 - #define HFA384x_TX_STRUCTYPE ((u16)GENMASK(4, 3)) 479 - #define HFA384x_TX_TXEX ((u16)BIT(2)) 480 - #define HFA384x_TX_TXOK ((u16)BIT(1)) 481 - /*-------------------------------------------------------------------- 482 - * Communication Frames: Test/Get/Set Field Values for Transmit Frames 483 - *-------------------------------------------------------------------- 484 - */ 485 - /*-- Status Field --*/ 486 - #define HFA384x_TXSTATUS_ISERROR(v) \ 487 - (((u16)(v)) & \ 488 - (HFA384x_TXSTATUS_ACKERR | HFA384x_TXSTATUS_FORMERR | \ 489 - HFA384x_TXSTATUS_DISCON | HFA384x_TXSTATUS_AGEDERR | \ 490 - HFA384x_TXSTATUS_RETRYERR)) 491 - 492 - #define HFA384x_TX_SET(v, m, s) ((((u16)(v)) << ((u16)(s))) & ((u16)(m))) 493 - 494 - #define HFA384x_TX_MACPORT_SET(v) HFA384x_TX_SET(v, HFA384x_TX_MACPORT, 8) 495 - #define HFA384x_TX_STRUCTYPE_SET(v) HFA384x_TX_SET(v, \ 496 - HFA384x_TX_STRUCTYPE, 3) 497 - #define HFA384x_TX_TXEX_SET(v) HFA384x_TX_SET(v, HFA384x_TX_TXEX, 2) 498 - #define HFA384x_TX_TXOK_SET(v) HFA384x_TX_SET(v, HFA384x_TX_TXOK, 1) 499 - /*-------------------------------------------------------------------- 500 - * Communication Frames: Receive Frames 501 - *-------------------------------------------------------------------- 502 - */ 503 - /*-- Communication Frame: Receive Frame Structure --*/ 504 - struct hfa384x_rx_frame { 505 - /*-- MAC rx descriptor (hfa384x byte order) --*/ 506 - u16 status; 507 - u32 time; 508 - u8 silence; 509 - u8 signal; 510 - u8 rate; 511 - u8 rx_flow; 512 - u16 reserved1; 513 - u16 reserved2; 514 - 515 - /*-- 802.11 Header Information (802.11 byte order) --*/ 516 - struct p80211_hdr hdr; 517 - __le16 data_len; /* hfa384x (little endian) format */ 518 - 519 - /*-- 802.3 Header Information --*/ 520 - u8 dest_addr[6]; 521 - u8 src_addr[6]; 522 - u16 data_length; /* IEEE? (big endian) format */ 523 - } __packed; 524 - /*-------------------------------------------------------------------- 525 - * Communication Frames: Field Masks for Receive Frames 526 - *-------------------------------------------------------------------- 527 - */ 528 - 529 - /*-- Status Fields --*/ 530 - #define HFA384x_RXSTATUS_MACPORT ((u16)GENMASK(10, 8)) 531 - #define HFA384x_RXSTATUS_FCSERR ((u16)BIT(0)) 532 - /*-------------------------------------------------------------------- 533 - * Communication Frames: Test/Get/Set Field Values for Receive Frames 534 - *-------------------------------------------------------------------- 535 - */ 536 - #define HFA384x_RXSTATUS_MACPORT_GET(value) ((u16)((((u16)(value)) \ 537 - & HFA384x_RXSTATUS_MACPORT) >> 8)) 538 - #define HFA384x_RXSTATUS_ISFCSERR(value) ((u16)(((u16)(value)) \ 539 - & HFA384x_RXSTATUS_FCSERR)) 540 - /*-------------------------------------------------------------------- 541 - * FRAME STRUCTURES: Information Types and Information Frame Structures 542 - *-------------------------------------------------------------------- 543 - * Information Types 544 - *-------------------------------------------------------------------- 545 - */ 546 - #define HFA384x_IT_HANDOVERADDR ((u16)0xF000UL) 547 - #define HFA384x_IT_COMMTALLIES ((u16)0xF100UL) 548 - #define HFA384x_IT_SCANRESULTS ((u16)0xF101UL) 549 - #define HFA384x_IT_CHINFORESULTS ((u16)0xF102UL) 550 - #define HFA384x_IT_HOSTSCANRESULTS ((u16)0xF103UL) 551 - #define HFA384x_IT_LINKSTATUS ((u16)0xF200UL) 552 - #define HFA384x_IT_ASSOCSTATUS ((u16)0xF201UL) 553 - #define HFA384x_IT_AUTHREQ ((u16)0xF202UL) 554 - #define HFA384x_IT_PSUSERCNT ((u16)0xF203UL) 555 - #define HFA384x_IT_KEYIDCHANGED ((u16)0xF204UL) 556 - #define HFA384x_IT_ASSOCREQ ((u16)0xF205UL) 557 - #define HFA384x_IT_MICFAILURE ((u16)0xF206UL) 558 - 559 - /*-------------------------------------------------------------------- 560 - * Information Frames Structures 561 - *-------------------------------------------------------------------- 562 - * Information Frames: Notification Frame Structures 563 - *-------------------------------------------------------------------- 564 - */ 565 - 566 - /*-- Inquiry Frame, Diagnose: Communication Tallies --*/ 567 - struct hfa384x_comm_tallies_16 { 568 - __le16 txunicastframes; 569 - __le16 txmulticastframes; 570 - __le16 txfragments; 571 - __le16 txunicastoctets; 572 - __le16 txmulticastoctets; 573 - __le16 txdeferredtrans; 574 - __le16 txsingleretryframes; 575 - __le16 txmultipleretryframes; 576 - __le16 txretrylimitexceeded; 577 - __le16 txdiscards; 578 - __le16 rxunicastframes; 579 - __le16 rxmulticastframes; 580 - __le16 rxfragments; 581 - __le16 rxunicastoctets; 582 - __le16 rxmulticastoctets; 583 - __le16 rxfcserrors; 584 - __le16 rxdiscardsnobuffer; 585 - __le16 txdiscardswrongsa; 586 - __le16 rxdiscardswepundecr; 587 - __le16 rxmsginmsgfrag; 588 - __le16 rxmsginbadmsgfrag; 589 - } __packed; 590 - 591 - struct hfa384x_comm_tallies_32 { 592 - __le32 txunicastframes; 593 - __le32 txmulticastframes; 594 - __le32 txfragments; 595 - __le32 txunicastoctets; 596 - __le32 txmulticastoctets; 597 - __le32 txdeferredtrans; 598 - __le32 txsingleretryframes; 599 - __le32 txmultipleretryframes; 600 - __le32 txretrylimitexceeded; 601 - __le32 txdiscards; 602 - __le32 rxunicastframes; 603 - __le32 rxmulticastframes; 604 - __le32 rxfragments; 605 - __le32 rxunicastoctets; 606 - __le32 rxmulticastoctets; 607 - __le32 rxfcserrors; 608 - __le32 rxdiscardsnobuffer; 609 - __le32 txdiscardswrongsa; 610 - __le32 rxdiscardswepundecr; 611 - __le32 rxmsginmsgfrag; 612 - __le32 rxmsginbadmsgfrag; 613 - } __packed; 614 - 615 - /*-- Inquiry Frame, Diagnose: Scan Results & Subfields--*/ 616 - struct hfa384x_scan_result_sub { 617 - u16 chid; 618 - u16 anl; 619 - u16 sl; 620 - u8 bssid[WLAN_BSSID_LEN]; 621 - u16 bcnint; 622 - u16 capinfo; 623 - struct hfa384x_bytestr32 ssid; 624 - u8 supprates[10]; /* 802.11 info element */ 625 - u16 proberesp_rate; 626 - } __packed; 627 - 628 - struct hfa384x_scan_result { 629 - u16 rsvd; 630 - u16 scanreason; 631 - struct hfa384x_scan_result_sub result[HFA384x_SCANRESULT_MAX]; 632 - } __packed; 633 - 634 - /*-- Inquiry Frame, Diagnose: ChInfo Results & Subfields--*/ 635 - struct hfa384x_ch_info_result_sub { 636 - u16 chid; 637 - u16 anl; 638 - u16 pnl; 639 - u16 active; 640 - } __packed; 641 - 642 - #define HFA384x_CHINFORESULT_BSSACTIVE BIT(0) 643 - #define HFA384x_CHINFORESULT_PCFACTIVE BIT(1) 644 - 645 - struct hfa384x_ch_info_result { 646 - u16 scanchannels; 647 - struct hfa384x_ch_info_result_sub result[HFA384x_CHINFORESULT_MAX]; 648 - } __packed; 649 - 650 - /*-- Inquiry Frame, Diagnose: Host Scan Results & Subfields--*/ 651 - struct hfa384x_hscan_result_sub { 652 - __le16 chid; 653 - __le16 anl; 654 - __le16 sl; 655 - u8 bssid[WLAN_BSSID_LEN]; 656 - __le16 bcnint; 657 - __le16 capinfo; 658 - struct hfa384x_bytestr32 ssid; 659 - u8 supprates[10]; /* 802.11 info element */ 660 - u16 proberesp_rate; 661 - __le16 atim; 662 - } __packed; 663 - 664 - struct hfa384x_hscan_result { 665 - u16 nresult; 666 - u16 rsvd; 667 - struct hfa384x_hscan_result_sub result[HFA384x_HSCANRESULT_MAX]; 668 - } __packed; 669 - 670 - /*-- Unsolicited Frame, MAC Mgmt: LinkStatus --*/ 671 - 672 - #define HFA384x_LINK_NOTCONNECTED ((u16)0) 673 - #define HFA384x_LINK_CONNECTED ((u16)1) 674 - #define HFA384x_LINK_DISCONNECTED ((u16)2) 675 - #define HFA384x_LINK_AP_CHANGE ((u16)3) 676 - #define HFA384x_LINK_AP_OUTOFRANGE ((u16)4) 677 - #define HFA384x_LINK_AP_INRANGE ((u16)5) 678 - #define HFA384x_LINK_ASSOCFAIL ((u16)6) 679 - 680 - struct hfa384x_link_status { 681 - __le16 linkstatus; 682 - } __packed; 683 - 684 - /*-- Unsolicited Frame, MAC Mgmt: AssociationStatus (--*/ 685 - 686 - #define HFA384x_ASSOCSTATUS_STAASSOC ((u16)1) 687 - #define HFA384x_ASSOCSTATUS_REASSOC ((u16)2) 688 - #define HFA384x_ASSOCSTATUS_AUTHFAIL ((u16)5) 689 - 690 - struct hfa384x_assoc_status { 691 - u16 assocstatus; 692 - u8 sta_addr[ETH_ALEN]; 693 - /* old_ap_addr is only valid if assocstatus == 2 */ 694 - u8 old_ap_addr[ETH_ALEN]; 695 - u16 reason; 696 - u16 reserved; 697 - } __packed; 698 - 699 - /*-- Unsolicited Frame, MAC Mgmt: AuthRequest (AP Only) --*/ 700 - 701 - struct hfa384x_auth_request { 702 - u8 sta_addr[ETH_ALEN]; 703 - __le16 algorithm; 704 - } __packed; 705 - 706 - /*-- Unsolicited Frame, MAC Mgmt: PSUserCount (AP Only) --*/ 707 - 708 - struct hfa384x_ps_user_count { 709 - __le16 usercnt; 710 - } __packed; 711 - 712 - struct hfa384x_key_id_changed { 713 - u8 sta_addr[ETH_ALEN]; 714 - u16 keyid; 715 - } __packed; 716 - 717 - /*-- Collection of all Inf frames ---------------*/ 718 - union hfa384x_infodata { 719 - struct hfa384x_comm_tallies_16 commtallies16; 720 - struct hfa384x_comm_tallies_32 commtallies32; 721 - struct hfa384x_scan_result scanresult; 722 - struct hfa384x_ch_info_result chinforesult; 723 - struct hfa384x_hscan_result hscanresult; 724 - struct hfa384x_link_status linkstatus; 725 - struct hfa384x_assoc_status assocstatus; 726 - struct hfa384x_auth_request authreq; 727 - struct hfa384x_ps_user_count psusercnt; 728 - struct hfa384x_key_id_changed keyidchanged; 729 - } __packed; 730 - 731 - struct hfa384x_inf_frame { 732 - u16 framelen; 733 - u16 infotype; 734 - union hfa384x_infodata info; 735 - } __packed; 736 - 737 - /*-------------------------------------------------------------------- 738 - * USB Packet structures and constants. 739 - *-------------------------------------------------------------------- 740 - */ 741 - 742 - /* Should be sent to the bulkout endpoint */ 743 - #define HFA384x_USB_TXFRM 0 744 - #define HFA384x_USB_CMDREQ 1 745 - #define HFA384x_USB_WRIDREQ 2 746 - #define HFA384x_USB_RRIDREQ 3 747 - #define HFA384x_USB_WMEMREQ 4 748 - #define HFA384x_USB_RMEMREQ 5 749 - 750 - /* Received from the bulkin endpoint */ 751 - #define HFA384x_USB_ISTXFRM(a) (((a) & 0x9000) == 0x1000) 752 - #define HFA384x_USB_ISRXFRM(a) (!((a) & 0x9000)) 753 - #define HFA384x_USB_INFOFRM 0x8000 754 - #define HFA384x_USB_CMDRESP 0x8001 755 - #define HFA384x_USB_WRIDRESP 0x8002 756 - #define HFA384x_USB_RRIDRESP 0x8003 757 - #define HFA384x_USB_WMEMRESP 0x8004 758 - #define HFA384x_USB_RMEMRESP 0x8005 759 - #define HFA384x_USB_BUFAVAIL 0x8006 760 - #define HFA384x_USB_ERROR 0x8007 761 - 762 - /*------------------------------------*/ 763 - /* Request (bulk OUT) packet contents */ 764 - 765 - struct hfa384x_usb_txfrm { 766 - struct hfa384x_tx_frame desc; 767 - u8 data[WLAN_DATA_MAXLEN]; 768 - } __packed; 769 - 770 - struct hfa384x_usb_cmdreq { 771 - __le16 type; 772 - __le16 cmd; 773 - __le16 parm0; 774 - __le16 parm1; 775 - __le16 parm2; 776 - u8 pad[54]; 777 - } __packed; 778 - 779 - struct hfa384x_usb_wridreq { 780 - __le16 type; 781 - __le16 frmlen; 782 - __le16 rid; 783 - u8 data[HFA384x_RIDDATA_MAXLEN]; 784 - } __packed; 785 - 786 - struct hfa384x_usb_rridreq { 787 - __le16 type; 788 - __le16 frmlen; 789 - __le16 rid; 790 - u8 pad[58]; 791 - } __packed; 792 - 793 - struct hfa384x_usb_wmemreq { 794 - __le16 type; 795 - __le16 frmlen; 796 - __le16 offset; 797 - __le16 page; 798 - u8 data[HFA384x_USB_RWMEM_MAXLEN]; 799 - } __packed; 800 - 801 - struct hfa384x_usb_rmemreq { 802 - __le16 type; 803 - __le16 frmlen; 804 - __le16 offset; 805 - __le16 page; 806 - u8 pad[56]; 807 - } __packed; 808 - 809 - /*------------------------------------*/ 810 - /* Response (bulk IN) packet contents */ 811 - 812 - struct hfa384x_usb_rxfrm { 813 - struct hfa384x_rx_frame desc; 814 - u8 data[WLAN_DATA_MAXLEN]; 815 - } __packed; 816 - 817 - struct hfa384x_usb_infofrm { 818 - u16 type; 819 - struct hfa384x_inf_frame info; 820 - } __packed; 821 - 822 - struct hfa384x_usb_statusresp { 823 - u16 type; 824 - __le16 status; 825 - __le16 resp0; 826 - __le16 resp1; 827 - __le16 resp2; 828 - } __packed; 829 - 830 - struct hfa384x_usb_rridresp { 831 - u16 type; 832 - __le16 frmlen; 833 - __le16 rid; 834 - u8 data[HFA384x_RIDDATA_MAXLEN]; 835 - } __packed; 836 - 837 - struct hfa384x_usb_rmemresp { 838 - u16 type; 839 - u16 frmlen; 840 - u8 data[HFA384x_USB_RWMEM_MAXLEN]; 841 - } __packed; 842 - 843 - struct hfa384x_usb_bufavail { 844 - u16 type; 845 - u16 frmlen; 846 - } __packed; 847 - 848 - struct hfa384x_usb_error { 849 - u16 type; 850 - u16 errortype; 851 - } __packed; 852 - 853 - /*----------------------------------------------------------*/ 854 - /* Unions for packaging all the known packet types together */ 855 - 856 - union hfa384x_usbout { 857 - __le16 type; 858 - struct hfa384x_usb_txfrm txfrm; 859 - struct hfa384x_usb_cmdreq cmdreq; 860 - struct hfa384x_usb_wridreq wridreq; 861 - struct hfa384x_usb_rridreq rridreq; 862 - struct hfa384x_usb_wmemreq wmemreq; 863 - struct hfa384x_usb_rmemreq rmemreq; 864 - } __packed; 865 - 866 - union hfa384x_usbin { 867 - __le16 type; 868 - struct hfa384x_usb_rxfrm rxfrm; 869 - struct hfa384x_usb_txfrm txfrm; 870 - struct hfa384x_usb_infofrm infofrm; 871 - struct hfa384x_usb_statusresp cmdresp; 872 - struct hfa384x_usb_statusresp wridresp; 873 - struct hfa384x_usb_rridresp rridresp; 874 - struct hfa384x_usb_statusresp wmemresp; 875 - struct hfa384x_usb_rmemresp rmemresp; 876 - struct hfa384x_usb_bufavail bufavail; 877 - struct hfa384x_usb_error usberror; 878 - u8 boguspad[3000]; 879 - } __packed; 880 - 881 - /*-------------------------------------------------------------------- 882 - * PD record structures. 883 - *-------------------------------------------------------------------- 884 - */ 885 - 886 - struct hfa384x_pdr_mfisuprange { 887 - u16 id; 888 - u16 variant; 889 - u16 bottom; 890 - u16 top; 891 - } __packed; 892 - 893 - struct hfa384x_pdr_cfisuprange { 894 - u16 id; 895 - u16 variant; 896 - u16 bottom; 897 - u16 top; 898 - } __packed; 899 - 900 - struct hfa384x_pdr_nicid { 901 - u16 id; 902 - u16 variant; 903 - u16 major; 904 - u16 minor; 905 - } __packed; 906 - 907 - struct hfa384x_pdrec { 908 - __le16 len; /* in words */ 909 - __le16 code; 910 - union pdr { 911 - struct hfa384x_pdr_mfisuprange mfisuprange; 912 - struct hfa384x_pdr_cfisuprange cfisuprange; 913 - struct hfa384x_pdr_nicid nicid; 914 - 915 - } data; 916 - } __packed; 917 - 918 - #ifdef __KERNEL__ 919 - /*-------------------------------------------------------------------- 920 - * --- MAC state structure, argument to all functions -- 921 - * --- Also, a collection of support types -- 922 - *-------------------------------------------------------------------- 923 - */ 924 - struct hfa384x_cmdresult { 925 - u16 status; 926 - u16 resp0; 927 - u16 resp1; 928 - u16 resp2; 929 - }; 930 - 931 - /* USB Control Exchange (CTLX): 932 - * A queue of the structure below is maintained for all of the 933 - * Request/Response type USB packets supported by Prism2. 934 - */ 935 - /* The following hfa384x_* structures are arguments to 936 - * the usercb() for the different CTLX types. 937 - */ 938 - struct hfa384x_rridresult { 939 - u16 rid; 940 - const void *riddata; 941 - unsigned int riddata_len; 942 - }; 943 - 944 - enum ctlx_state { 945 - CTLX_START = 0, /* Start state, not queued */ 946 - 947 - CTLX_COMPLETE, /* CTLX successfully completed */ 948 - CTLX_REQ_FAILED, /* OUT URB completed w/ error */ 949 - 950 - CTLX_PENDING, /* Queued, data valid */ 951 - CTLX_REQ_SUBMITTED, /* OUT URB submitted */ 952 - CTLX_REQ_COMPLETE, /* OUT URB complete */ 953 - CTLX_RESP_COMPLETE /* IN URB received */ 954 - }; 955 - 956 - struct hfa384x_usbctlx; 957 - struct hfa384x; 958 - 959 - typedef void (*ctlx_cmdcb_t) (struct hfa384x *, const struct hfa384x_usbctlx *); 960 - 961 - typedef void (*ctlx_usercb_t) (struct hfa384x *hw, 962 - void *ctlxresult, void *usercb_data); 963 - 964 - struct hfa384x_usbctlx { 965 - struct list_head list; 966 - 967 - size_t outbufsize; 968 - union hfa384x_usbout outbuf; /* pkt buf for OUT */ 969 - union hfa384x_usbin inbuf; /* pkt buf for IN(a copy) */ 970 - 971 - enum ctlx_state state; /* Tracks running state */ 972 - 973 - struct completion done; 974 - int reapable; /* Food for the reaper task */ 975 - 976 - ctlx_cmdcb_t cmdcb; /* Async command callback */ 977 - ctlx_usercb_t usercb; /* Async user callback, */ 978 - void *usercb_data; /* at CTLX completion */ 979 - }; 980 - 981 - struct hfa384x_usbctlxq { 982 - spinlock_t lock; 983 - struct list_head pending; 984 - struct list_head active; 985 - struct list_head completing; 986 - struct list_head reapable; 987 - }; 988 - 989 - struct hfa384x_metacmd { 990 - u16 cmd; 991 - 992 - u16 parm0; 993 - u16 parm1; 994 - u16 parm2; 995 - 996 - struct hfa384x_cmdresult result; 997 - }; 998 - 999 - #define MAX_GRP_ADDR 32 1000 - #define WLAN_COMMENT_MAX 80 /* Max. length of user comment string. */ 1001 - 1002 - #define WLAN_AUTH_MAX 60 /* Max. # of authenticated stations. */ 1003 - #define WLAN_ACCESS_MAX 60 /* Max. # of stations in an access list. */ 1004 - #define WLAN_ACCESS_NONE 0 /* No stations may be authenticated. */ 1005 - #define WLAN_ACCESS_ALL 1 /* All stations may be authenticated. */ 1006 - #define WLAN_ACCESS_ALLOW 2 /* Authenticate only "allowed" stations. */ 1007 - #define WLAN_ACCESS_DENY 3 /* Do not authenticate "denied" stations. */ 1008 - 1009 - /* XXX These are going away ASAP */ 1010 - struct prism2sta_authlist { 1011 - unsigned int cnt; 1012 - u8 addr[WLAN_AUTH_MAX][ETH_ALEN]; 1013 - u8 assoc[WLAN_AUTH_MAX]; 1014 - }; 1015 - 1016 - struct prism2sta_accesslist { 1017 - unsigned int modify; 1018 - unsigned int cnt; 1019 - u8 addr[WLAN_ACCESS_MAX][ETH_ALEN]; 1020 - unsigned int cnt1; 1021 - u8 addr1[WLAN_ACCESS_MAX][ETH_ALEN]; 1022 - }; 1023 - 1024 - struct hfa384x { 1025 - /* USB support data */ 1026 - struct usb_device *usb; 1027 - struct urb rx_urb; 1028 - struct sk_buff *rx_urb_skb; 1029 - struct urb tx_urb; 1030 - struct urb ctlx_urb; 1031 - union hfa384x_usbout txbuff; 1032 - struct hfa384x_usbctlxq ctlxq; 1033 - struct timer_list reqtimer; 1034 - struct timer_list resptimer; 1035 - 1036 - struct timer_list throttle; 1037 - 1038 - struct work_struct reaper_bh; 1039 - struct work_struct completion_bh; 1040 - 1041 - struct work_struct usb_work; 1042 - 1043 - unsigned long usb_flags; 1044 - #define THROTTLE_RX 0 1045 - #define THROTTLE_TX 1 1046 - #define WORK_RX_HALT 2 1047 - #define WORK_TX_HALT 3 1048 - #define WORK_RX_RESUME 4 1049 - #define WORK_TX_RESUME 5 1050 - 1051 - unsigned short req_timer_done:1; 1052 - unsigned short resp_timer_done:1; 1053 - 1054 - int endp_in; 1055 - int endp_out; 1056 - 1057 - int sniff_fcs; 1058 - int sniff_channel; 1059 - int sniff_truncate; 1060 - int sniffhdr; 1061 - 1062 - wait_queue_head_t cmdq; /* wait queue itself */ 1063 - 1064 - /* Controller state */ 1065 - u32 state; 1066 - u32 isap; 1067 - u8 port_enabled[HFA384x_NUMPORTS_MAX]; 1068 - 1069 - /* Download support */ 1070 - unsigned int dlstate; 1071 - struct hfa384x_downloadbuffer bufinfo; 1072 - u16 dltimeout; 1073 - 1074 - int scanflag; /* to signal scan complete */ 1075 - int join_ap; /* are we joined to a specific ap */ 1076 - int join_retries; /* number of join retries till we fail */ 1077 - struct hfa384x_join_request_data joinreq;/* join request saved data */ 1078 - 1079 - struct wlandevice *wlandev; 1080 - /* Timer to allow for the deferred processing of linkstatus messages */ 1081 - struct work_struct link_bh; 1082 - 1083 - struct work_struct commsqual_bh; 1084 - struct hfa384x_commsquality qual; 1085 - struct timer_list commsqual_timer; 1086 - 1087 - u16 link_status; 1088 - u16 link_status_new; 1089 - struct sk_buff_head authq; 1090 - 1091 - u32 txrate; 1092 - 1093 - /* And here we have stuff that used to be in priv */ 1094 - 1095 - /* State variables */ 1096 - unsigned int presniff_port_type; 1097 - u16 presniff_wepflags; 1098 - u32 dot11_desired_bss_type; 1099 - 1100 - int dbmadjust; 1101 - 1102 - /* Group Addresses - right now, there are up to a total 1103 - * of MAX_GRP_ADDR group addresses 1104 - */ 1105 - u8 dot11_grp_addr[MAX_GRP_ADDR][ETH_ALEN]; 1106 - unsigned int dot11_grpcnt; 1107 - 1108 - /* Component Identities */ 1109 - struct hfa384x_compident ident_nic; 1110 - struct hfa384x_compident ident_pri_fw; 1111 - struct hfa384x_compident ident_sta_fw; 1112 - struct hfa384x_compident ident_ap_fw; 1113 - u16 mm_mods; 1114 - 1115 - /* Supplier compatibility ranges */ 1116 - struct hfa384x_caplevel cap_sup_mfi; 1117 - struct hfa384x_caplevel cap_sup_cfi; 1118 - struct hfa384x_caplevel cap_sup_pri; 1119 - struct hfa384x_caplevel cap_sup_sta; 1120 - struct hfa384x_caplevel cap_sup_ap; 1121 - 1122 - /* Actor compatibility ranges */ 1123 - struct hfa384x_caplevel cap_act_pri_cfi; /* 1124 - * pri f/w to controller 1125 - * interface 1126 - */ 1127 - 1128 - struct hfa384x_caplevel cap_act_sta_cfi; /* 1129 - * sta f/w to controller 1130 - * interface 1131 - */ 1132 - 1133 - struct hfa384x_caplevel cap_act_sta_mfi; /* 1134 - * sta f/w to modem interface 1135 - */ 1136 - 1137 - struct hfa384x_caplevel cap_act_ap_cfi; /* 1138 - * ap f/w to controller 1139 - * interface 1140 - */ 1141 - 1142 - struct hfa384x_caplevel cap_act_ap_mfi; /* ap f/w to modem interface */ 1143 - 1144 - u32 psusercount; /* Power save user count. */ 1145 - struct hfa384x_comm_tallies_32 tallies; /* Communication tallies. */ 1146 - u8 comment[WLAN_COMMENT_MAX + 1]; /* User comment */ 1147 - 1148 - /* Channel Info request results (AP only) */ 1149 - struct { 1150 - atomic_t done; 1151 - u8 count; 1152 - struct hfa384x_ch_info_result results; 1153 - } channel_info; 1154 - 1155 - struct hfa384x_inf_frame *scanresults; 1156 - 1157 - struct prism2sta_authlist authlist; /* 1158 - * Authenticated station list. 1159 - */ 1160 - unsigned int accessmode; /* Access mode. */ 1161 - struct prism2sta_accesslist allow; /* Allowed station list. */ 1162 - struct prism2sta_accesslist deny; /* Denied station list. */ 1163 - 1164 - }; 1165 - 1166 - void hfa384x_create(struct hfa384x *hw, struct usb_device *usb); 1167 - void hfa384x_destroy(struct hfa384x *hw); 1168 - 1169 - int hfa384x_corereset(struct hfa384x *hw, int holdtime, int settletime, 1170 - int genesis); 1171 - int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport); 1172 - int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport); 1173 - int hfa384x_drvr_flashdl_enable(struct hfa384x *hw); 1174 - int hfa384x_drvr_flashdl_disable(struct hfa384x *hw); 1175 - int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr, void *buf, 1176 - u32 len); 1177 - int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len); 1178 - int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr); 1179 - int hfa384x_drvr_ramdl_disable(struct hfa384x *hw); 1180 - int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len); 1181 - int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len); 1182 - int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len); 1183 - 1184 - static inline int 1185 - hfa384x_drvr_getconfig16(struct hfa384x *hw, u16 rid, void *val) 1186 - { 1187 - int result = 0; 1188 - 1189 - result = hfa384x_drvr_getconfig(hw, rid, val, sizeof(u16)); 1190 - if (result == 0) 1191 - le16_to_cpus(val); 1192 - return result; 1193 - } 1194 - 1195 - static inline int hfa384x_drvr_setconfig16(struct hfa384x *hw, u16 rid, u16 val) 1196 - { 1197 - __le16 value = cpu_to_le16(val); 1198 - 1199 - return hfa384x_drvr_setconfig(hw, rid, &value, sizeof(value)); 1200 - } 1201 - 1202 - int 1203 - hfa384x_drvr_setconfig_async(struct hfa384x *hw, 1204 - u16 rid, 1205 - void *buf, 1206 - u16 len, ctlx_usercb_t usercb, void *usercb_data); 1207 - 1208 - static inline int 1209 - hfa384x_drvr_setconfig16_async(struct hfa384x *hw, u16 rid, u16 val) 1210 - { 1211 - __le16 value = cpu_to_le16(val); 1212 - 1213 - return hfa384x_drvr_setconfig_async(hw, rid, &value, sizeof(value), 1214 - NULL, NULL); 1215 - } 1216 - 1217 - int hfa384x_drvr_start(struct hfa384x *hw); 1218 - int hfa384x_drvr_stop(struct hfa384x *hw); 1219 - int 1220 - hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb, 1221 - struct p80211_hdr *p80211_hdr, 1222 - struct p80211_metawep *p80211_wep); 1223 - void hfa384x_tx_timeout(struct wlandevice *wlandev); 1224 - 1225 - int hfa384x_cmd_initialize(struct hfa384x *hw); 1226 - int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport); 1227 - int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport); 1228 - int hfa384x_cmd_allocate(struct hfa384x *hw, u16 len); 1229 - int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable); 1230 - int 1231 - hfa384x_cmd_download(struct hfa384x *hw, 1232 - u16 mode, u16 lowaddr, u16 highaddr, u16 codelen); 1233 - 1234 - #endif /*__KERNEL__ */ 1235 - 1236 - #endif /*_HFA384x_H */
-3880
drivers/staging/wlan-ng/hfa384x_usb.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Functions that talk to the USB variant of the Intersil hfa384x MAC 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file implements functions that correspond to the prism2/hfa384x 28 - * 802.11 MAC hardware and firmware host interface. 29 - * 30 - * The functions can be considered to represent several levels of 31 - * abstraction. The lowest level functions are simply C-callable wrappers 32 - * around the register accesses. The next higher level represents C-callable 33 - * prism2 API functions that match the Intersil documentation as closely 34 - * as is reasonable. The next higher layer implements common sequences 35 - * of invocations of the API layer (e.g. write to bap, followed by cmd). 36 - * 37 - * Common sequences: 38 - * hfa384x_drvr_xxx Highest level abstractions provided by the 39 - * hfa384x code. They are driver defined wrappers 40 - * for common sequences. These functions generally 41 - * use the services of the lower levels. 42 - * 43 - * hfa384x_drvr_xxxconfig An example of the drvr level abstraction. These 44 - * functions are wrappers for the RID get/set 45 - * sequence. They call copy_[to|from]_bap() and 46 - * cmd_access(). These functions operate on the 47 - * RIDs and buffers without validation. The caller 48 - * is responsible for that. 49 - * 50 - * API wrapper functions: 51 - * hfa384x_cmd_xxx functions that provide access to the f/w commands. 52 - * The function arguments correspond to each command 53 - * argument, even command arguments that get packed 54 - * into single registers. These functions _just_ 55 - * issue the command by setting the cmd/parm regs 56 - * & reading the status/resp regs. Additional 57 - * activities required to fully use a command 58 - * (read/write from/to bap, get/set int status etc.) 59 - * are implemented separately. Think of these as 60 - * C-callable prism2 commands. 61 - * 62 - * Lowest Layer Functions: 63 - * hfa384x_docmd_xxx These functions implement the sequence required 64 - * to issue any prism2 command. Primarily used by the 65 - * hfa384x_cmd_xxx functions. 66 - * 67 - * hfa384x_bap_xxx BAP read/write access functions. 68 - * Note: we usually use BAP0 for non-interrupt context 69 - * and BAP1 for interrupt context. 70 - * 71 - * hfa384x_dl_xxx download related functions. 72 - * 73 - * Driver State Issues: 74 - * Note that there are two pairs of functions that manage the 75 - * 'initialized' and 'running' states of the hw/MAC combo. The four 76 - * functions are create(), destroy(), start(), and stop(). create() 77 - * sets up the data structures required to support the hfa384x_* 78 - * functions and destroy() cleans them up. The start() function gets 79 - * the actual hardware running and enables the interrupts. The stop() 80 - * function shuts the hardware down. The sequence should be: 81 - * create() 82 - * start() 83 - * . 84 - * . Do interesting things w/ the hardware 85 - * . 86 - * stop() 87 - * destroy() 88 - * 89 - * Note that destroy() can be called without calling stop() first. 90 - * -------------------------------------------------------------------- 91 - */ 92 - 93 - #include <linux/module.h> 94 - #include <linux/kernel.h> 95 - #include <linux/sched.h> 96 - #include <linux/types.h> 97 - #include <linux/slab.h> 98 - #include <linux/wireless.h> 99 - #include <linux/netdevice.h> 100 - #include <linux/timer.h> 101 - #include <linux/io.h> 102 - #include <linux/delay.h> 103 - #include <asm/byteorder.h> 104 - #include <linux/bitops.h> 105 - #include <linux/list.h> 106 - #include <linux/usb.h> 107 - #include <linux/byteorder/generic.h> 108 - 109 - #include "p80211types.h" 110 - #include "p80211hdr.h" 111 - #include "p80211mgmt.h" 112 - #include "p80211conv.h" 113 - #include "p80211msg.h" 114 - #include "p80211netdev.h" 115 - #include "p80211req.h" 116 - #include "p80211metadef.h" 117 - #include "p80211metastruct.h" 118 - #include "hfa384x.h" 119 - #include "prism2mgmt.h" 120 - 121 - enum cmd_mode { 122 - DOWAIT = 0, 123 - DOASYNC 124 - }; 125 - 126 - #define THROTTLE_JIFFIES (HZ / 8) 127 - #define URB_ASYNC_UNLINK 0 128 - #define USB_QUEUE_BULK 0 129 - 130 - #define ROUNDUP64(a) (((a) + 63) & ~63) 131 - 132 - #ifdef DEBUG_USB 133 - static void dbprint_urb(struct urb *urb); 134 - #endif 135 - 136 - static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, 137 - struct hfa384x_usb_rxfrm *rxfrm); 138 - 139 - static void hfa384x_usb_defer(struct work_struct *data); 140 - 141 - static int submit_rx_urb(struct hfa384x *hw, gfp_t flags); 142 - 143 - static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t flags); 144 - 145 - /*---------------------------------------------------*/ 146 - /* Callbacks */ 147 - static void hfa384x_usbout_callback(struct urb *urb); 148 - static void hfa384x_ctlxout_callback(struct urb *urb); 149 - static void hfa384x_usbin_callback(struct urb *urb); 150 - 151 - static void 152 - hfa384x_usbin_txcompl(struct wlandevice *wlandev, union hfa384x_usbin *usbin); 153 - 154 - static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb); 155 - 156 - static void hfa384x_usbin_info(struct wlandevice *wlandev, 157 - union hfa384x_usbin *usbin); 158 - 159 - static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin, 160 - int urb_status); 161 - 162 - /*---------------------------------------------------*/ 163 - /* Functions to support the prism2 usb command queue */ 164 - 165 - static void hfa384x_usbctlxq_run(struct hfa384x *hw); 166 - 167 - static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t); 168 - 169 - static void hfa384x_usbctlx_resptimerfn(struct timer_list *t); 170 - 171 - static void hfa384x_usb_throttlefn(struct timer_list *t); 172 - 173 - static void hfa384x_usbctlx_completion_task(struct work_struct *work); 174 - 175 - static void hfa384x_usbctlx_reaper_task(struct work_struct *work); 176 - 177 - static int hfa384x_usbctlx_submit(struct hfa384x *hw, 178 - struct hfa384x_usbctlx *ctlx); 179 - 180 - static void unlocked_usbctlx_complete(struct hfa384x *hw, 181 - struct hfa384x_usbctlx *ctlx); 182 - 183 - struct usbctlx_completor { 184 - int (*complete)(struct usbctlx_completor *completor); 185 - }; 186 - 187 - static int 188 - hfa384x_usbctlx_complete_sync(struct hfa384x *hw, 189 - struct hfa384x_usbctlx *ctlx, 190 - struct usbctlx_completor *completor); 191 - 192 - static int 193 - unlocked_usbctlx_cancel_async(struct hfa384x *hw, struct hfa384x_usbctlx *ctlx); 194 - 195 - static void hfa384x_cb_status(struct hfa384x *hw, 196 - const struct hfa384x_usbctlx *ctlx); 197 - 198 - static int 199 - usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp, 200 - struct hfa384x_cmdresult *result); 201 - 202 - static void 203 - usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp, 204 - struct hfa384x_rridresult *result); 205 - 206 - /*---------------------------------------------------*/ 207 - /* Low level req/resp CTLX formatters and submitters */ 208 - static inline int 209 - hfa384x_docmd(struct hfa384x *hw, 210 - struct hfa384x_metacmd *cmd); 211 - 212 - static int 213 - hfa384x_dorrid(struct hfa384x *hw, 214 - enum cmd_mode mode, 215 - u16 rid, 216 - void *riddata, 217 - unsigned int riddatalen, 218 - ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); 219 - 220 - static int 221 - hfa384x_dowrid(struct hfa384x *hw, 222 - enum cmd_mode mode, 223 - u16 rid, 224 - void *riddata, 225 - unsigned int riddatalen, 226 - ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data); 227 - 228 - static int 229 - hfa384x_dormem(struct hfa384x *hw, 230 - u16 page, 231 - u16 offset, 232 - void *data, 233 - unsigned int len); 234 - 235 - static int 236 - hfa384x_dowmem(struct hfa384x *hw, 237 - u16 page, 238 - u16 offset, 239 - void *data, 240 - unsigned int len); 241 - 242 - static int hfa384x_isgood_pdrcode(u16 pdrcode); 243 - 244 - static inline const char *ctlxstr(enum ctlx_state s) 245 - { 246 - static const char * const ctlx_str[] = { 247 - "Initial state", 248 - "Complete", 249 - "Request failed", 250 - "Request pending", 251 - "Request packet submitted", 252 - "Request packet completed", 253 - "Response packet completed" 254 - }; 255 - 256 - return ctlx_str[s]; 257 - }; 258 - 259 - static inline struct hfa384x_usbctlx *get_active_ctlx(struct hfa384x *hw) 260 - { 261 - return list_entry(hw->ctlxq.active.next, struct hfa384x_usbctlx, list); 262 - } 263 - 264 - #ifdef DEBUG_USB 265 - void dbprint_urb(struct urb *urb) 266 - { 267 - pr_debug("urb->pipe=0x%08x\n", urb->pipe); 268 - pr_debug("urb->status=0x%08x\n", urb->status); 269 - pr_debug("urb->transfer_flags=0x%08x\n", urb->transfer_flags); 270 - pr_debug("urb->transfer_buffer=0x%08x\n", 271 - (unsigned int)urb->transfer_buffer); 272 - pr_debug("urb->transfer_buffer_length=0x%08x\n", 273 - urb->transfer_buffer_length); 274 - pr_debug("urb->actual_length=0x%08x\n", urb->actual_length); 275 - pr_debug("urb->setup_packet(ctl)=0x%08x\n", 276 - (unsigned int)urb->setup_packet); 277 - pr_debug("urb->start_frame(iso/irq)=0x%08x\n", urb->start_frame); 278 - pr_debug("urb->interval(irq)=0x%08x\n", urb->interval); 279 - pr_debug("urb->error_count(iso)=0x%08x\n", urb->error_count); 280 - pr_debug("urb->context=0x%08x\n", (unsigned int)urb->context); 281 - pr_debug("urb->complete=0x%08x\n", (unsigned int)urb->complete); 282 - } 283 - #endif 284 - 285 - /*---------------------------------------------------------------- 286 - * submit_rx_urb 287 - * 288 - * Listen for input data on the BULK-IN pipe. If the pipe has 289 - * stalled then schedule it to be reset. 290 - * 291 - * Arguments: 292 - * hw device struct 293 - * memflags memory allocation flags 294 - * 295 - * Returns: 296 - * error code from submission 297 - * 298 - * Call context: 299 - * Any 300 - *---------------------------------------------------------------- 301 - */ 302 - static int submit_rx_urb(struct hfa384x *hw, gfp_t memflags) 303 - { 304 - struct sk_buff *skb; 305 - int result; 306 - 307 - skb = dev_alloc_skb(sizeof(union hfa384x_usbin)); 308 - if (!skb) { 309 - result = -ENOMEM; 310 - goto done; 311 - } 312 - 313 - /* Post the IN urb */ 314 - usb_fill_bulk_urb(&hw->rx_urb, hw->usb, 315 - hw->endp_in, 316 - skb->data, sizeof(union hfa384x_usbin), 317 - hfa384x_usbin_callback, hw->wlandev); 318 - 319 - hw->rx_urb_skb = skb; 320 - 321 - result = -ENOLINK; 322 - if (!hw->wlandev->hwremoved && 323 - !test_bit(WORK_RX_HALT, &hw->usb_flags)) { 324 - result = usb_submit_urb(&hw->rx_urb, memflags); 325 - 326 - /* Check whether we need to reset the RX pipe */ 327 - if (result == -EPIPE) { 328 - netdev_warn(hw->wlandev->netdev, 329 - "%s rx pipe stalled: requesting reset\n", 330 - hw->wlandev->netdev->name); 331 - if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags)) 332 - schedule_work(&hw->usb_work); 333 - } 334 - } 335 - 336 - /* Don't leak memory if anything should go wrong */ 337 - if (result != 0) { 338 - dev_kfree_skb(skb); 339 - hw->rx_urb_skb = NULL; 340 - } 341 - 342 - done: 343 - return result; 344 - } 345 - 346 - /*---------------------------------------------------------------- 347 - * submit_tx_urb 348 - * 349 - * Prepares and submits the URB of transmitted data. If the 350 - * submission fails then it will schedule the output pipe to 351 - * be reset. 352 - * 353 - * Arguments: 354 - * hw device struct 355 - * tx_urb URB of data for transmission 356 - * memflags memory allocation flags 357 - * 358 - * Returns: 359 - * error code from submission 360 - * 361 - * Call context: 362 - * Any 363 - *---------------------------------------------------------------- 364 - */ 365 - static int submit_tx_urb(struct hfa384x *hw, struct urb *tx_urb, gfp_t memflags) 366 - { 367 - struct net_device *netdev = hw->wlandev->netdev; 368 - int result; 369 - 370 - result = -ENOLINK; 371 - if (netif_running(netdev)) { 372 - if (!hw->wlandev->hwremoved && 373 - !test_bit(WORK_TX_HALT, &hw->usb_flags)) { 374 - result = usb_submit_urb(tx_urb, memflags); 375 - 376 - /* Test whether we need to reset the TX pipe */ 377 - if (result == -EPIPE) { 378 - netdev_warn(hw->wlandev->netdev, 379 - "%s tx pipe stalled: requesting reset\n", 380 - netdev->name); 381 - set_bit(WORK_TX_HALT, &hw->usb_flags); 382 - schedule_work(&hw->usb_work); 383 - } else if (result == 0) { 384 - netif_stop_queue(netdev); 385 - } 386 - } 387 - } 388 - 389 - return result; 390 - } 391 - 392 - /*---------------------------------------------------------------- 393 - * hfa394x_usb_defer 394 - * 395 - * There are some things that the USB stack cannot do while 396 - * in interrupt context, so we arrange this function to run 397 - * in process context. 398 - * 399 - * Arguments: 400 - * hw device structure 401 - * 402 - * Returns: 403 - * nothing 404 - * 405 - * Call context: 406 - * process (by design) 407 - *---------------------------------------------------------------- 408 - */ 409 - static void hfa384x_usb_defer(struct work_struct *data) 410 - { 411 - struct hfa384x *hw = container_of(data, struct hfa384x, usb_work); 412 - struct net_device *netdev = hw->wlandev->netdev; 413 - 414 - /* Don't bother trying to reset anything if the plug 415 - * has been pulled ... 416 - */ 417 - if (hw->wlandev->hwremoved) 418 - return; 419 - 420 - /* Reception has stopped: try to reset the input pipe */ 421 - if (test_bit(WORK_RX_HALT, &hw->usb_flags)) { 422 - int ret; 423 - 424 - usb_kill_urb(&hw->rx_urb); /* Cannot be holding spinlock! */ 425 - 426 - ret = usb_clear_halt(hw->usb, hw->endp_in); 427 - if (ret != 0) { 428 - netdev_err(hw->wlandev->netdev, 429 - "Failed to clear rx pipe for %s: err=%d\n", 430 - netdev->name, ret); 431 - } else { 432 - netdev_info(hw->wlandev->netdev, "%s rx pipe reset complete.\n", 433 - netdev->name); 434 - clear_bit(WORK_RX_HALT, &hw->usb_flags); 435 - set_bit(WORK_RX_RESUME, &hw->usb_flags); 436 - } 437 - } 438 - 439 - /* Resume receiving data back from the device. */ 440 - if (test_bit(WORK_RX_RESUME, &hw->usb_flags)) { 441 - int ret; 442 - 443 - ret = submit_rx_urb(hw, GFP_KERNEL); 444 - if (ret != 0) { 445 - netdev_err(hw->wlandev->netdev, 446 - "Failed to resume %s rx pipe.\n", 447 - netdev->name); 448 - } else { 449 - clear_bit(WORK_RX_RESUME, &hw->usb_flags); 450 - } 451 - } 452 - 453 - /* Transmission has stopped: try to reset the output pipe */ 454 - if (test_bit(WORK_TX_HALT, &hw->usb_flags)) { 455 - int ret; 456 - 457 - usb_kill_urb(&hw->tx_urb); 458 - ret = usb_clear_halt(hw->usb, hw->endp_out); 459 - if (ret != 0) { 460 - netdev_err(hw->wlandev->netdev, 461 - "Failed to clear tx pipe for %s: err=%d\n", 462 - netdev->name, ret); 463 - } else { 464 - netdev_info(hw->wlandev->netdev, "%s tx pipe reset complete.\n", 465 - netdev->name); 466 - clear_bit(WORK_TX_HALT, &hw->usb_flags); 467 - set_bit(WORK_TX_RESUME, &hw->usb_flags); 468 - 469 - /* Stopping the BULK-OUT pipe also blocked 470 - * us from sending any more CTLX URBs, so 471 - * we need to re-run our queue ... 472 - */ 473 - hfa384x_usbctlxq_run(hw); 474 - } 475 - } 476 - 477 - /* Resume transmitting. */ 478 - if (test_and_clear_bit(WORK_TX_RESUME, &hw->usb_flags)) 479 - netif_wake_queue(hw->wlandev->netdev); 480 - } 481 - 482 - /*---------------------------------------------------------------- 483 - * hfa384x_create 484 - * 485 - * Sets up the struct hfa384x data structure for use. Note this 486 - * does _not_ initialize the actual hardware, just the data structures 487 - * we use to keep track of its state. 488 - * 489 - * Arguments: 490 - * hw device structure 491 - * irq device irq number 492 - * iobase i/o base address for register access 493 - * membase memory base address for register access 494 - * 495 - * Returns: 496 - * nothing 497 - * 498 - * Side effects: 499 - * 500 - * Call context: 501 - * process 502 - *---------------------------------------------------------------- 503 - */ 504 - void hfa384x_create(struct hfa384x *hw, struct usb_device *usb) 505 - { 506 - hw->usb = usb; 507 - 508 - /* Set up the waitq */ 509 - init_waitqueue_head(&hw->cmdq); 510 - 511 - /* Initialize the command queue */ 512 - spin_lock_init(&hw->ctlxq.lock); 513 - INIT_LIST_HEAD(&hw->ctlxq.pending); 514 - INIT_LIST_HEAD(&hw->ctlxq.active); 515 - INIT_LIST_HEAD(&hw->ctlxq.completing); 516 - INIT_LIST_HEAD(&hw->ctlxq.reapable); 517 - 518 - /* Initialize the authentication queue */ 519 - skb_queue_head_init(&hw->authq); 520 - 521 - INIT_WORK(&hw->reaper_bh, hfa384x_usbctlx_reaper_task); 522 - INIT_WORK(&hw->completion_bh, hfa384x_usbctlx_completion_task); 523 - INIT_WORK(&hw->link_bh, prism2sta_processing_defer); 524 - INIT_WORK(&hw->usb_work, hfa384x_usb_defer); 525 - 526 - timer_setup(&hw->throttle, hfa384x_usb_throttlefn, 0); 527 - 528 - timer_setup(&hw->resptimer, hfa384x_usbctlx_resptimerfn, 0); 529 - 530 - timer_setup(&hw->reqtimer, hfa384x_usbctlx_reqtimerfn, 0); 531 - 532 - usb_init_urb(&hw->rx_urb); 533 - usb_init_urb(&hw->tx_urb); 534 - usb_init_urb(&hw->ctlx_urb); 535 - 536 - hw->link_status = HFA384x_LINK_NOTCONNECTED; 537 - hw->state = HFA384x_STATE_INIT; 538 - 539 - INIT_WORK(&hw->commsqual_bh, prism2sta_commsqual_defer); 540 - timer_setup(&hw->commsqual_timer, prism2sta_commsqual_timer, 0); 541 - } 542 - 543 - /*---------------------------------------------------------------- 544 - * hfa384x_destroy 545 - * 546 - * Partner to hfa384x_create(). This function cleans up the hw 547 - * structure so that it can be freed by the caller using a simple 548 - * kfree. Currently, this function is just a placeholder. If, at some 549 - * point in the future, an hw in the 'shutdown' state requires a 'deep' 550 - * kfree, this is where it should be done. Note that if this function 551 - * is called on a _running_ hw structure, the drvr_stop() function is 552 - * called. 553 - * 554 - * Arguments: 555 - * hw device structure 556 - * 557 - * Returns: 558 - * nothing, this function is not allowed to fail. 559 - * 560 - * Side effects: 561 - * 562 - * Call context: 563 - * process 564 - *---------------------------------------------------------------- 565 - */ 566 - void hfa384x_destroy(struct hfa384x *hw) 567 - { 568 - struct sk_buff *skb; 569 - 570 - if (hw->state == HFA384x_STATE_RUNNING) 571 - hfa384x_drvr_stop(hw); 572 - hw->state = HFA384x_STATE_PREINIT; 573 - 574 - kfree(hw->scanresults); 575 - hw->scanresults = NULL; 576 - 577 - /* Now to clean out the auth queue */ 578 - while ((skb = skb_dequeue(&hw->authq))) 579 - dev_kfree_skb(skb); 580 - } 581 - 582 - static struct hfa384x_usbctlx *usbctlx_alloc(void) 583 - { 584 - struct hfa384x_usbctlx *ctlx; 585 - 586 - ctlx = kzalloc(sizeof(*ctlx), 587 - in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); 588 - if (ctlx) 589 - init_completion(&ctlx->done); 590 - 591 - return ctlx; 592 - } 593 - 594 - static int 595 - usbctlx_get_status(const struct hfa384x_usb_statusresp *cmdresp, 596 - struct hfa384x_cmdresult *result) 597 - { 598 - result->status = le16_to_cpu(cmdresp->status); 599 - result->resp0 = le16_to_cpu(cmdresp->resp0); 600 - result->resp1 = le16_to_cpu(cmdresp->resp1); 601 - result->resp2 = le16_to_cpu(cmdresp->resp2); 602 - 603 - pr_debug("cmdresult:status=0x%04x resp0=0x%04x resp1=0x%04x resp2=0x%04x\n", 604 - result->status, result->resp0, result->resp1, result->resp2); 605 - 606 - return result->status & HFA384x_STATUS_RESULT; 607 - } 608 - 609 - static void 610 - usbctlx_get_rridresult(const struct hfa384x_usb_rridresp *rridresp, 611 - struct hfa384x_rridresult *result) 612 - { 613 - result->rid = le16_to_cpu(rridresp->rid); 614 - result->riddata = rridresp->data; 615 - result->riddata_len = ((le16_to_cpu(rridresp->frmlen) - 1) * 2); 616 - } 617 - 618 - /*---------------------------------------------------------------- 619 - * Completor object: 620 - * This completor must be passed to hfa384x_usbctlx_complete_sync() 621 - * when processing a CTLX that returns a struct hfa384x_cmdresult structure. 622 - *---------------------------------------------------------------- 623 - */ 624 - struct usbctlx_cmd_completor { 625 - struct usbctlx_completor head; 626 - 627 - const struct hfa384x_usb_statusresp *cmdresp; 628 - struct hfa384x_cmdresult *result; 629 - }; 630 - 631 - static inline int usbctlx_cmd_completor_fn(struct usbctlx_completor *head) 632 - { 633 - struct usbctlx_cmd_completor *complete; 634 - 635 - complete = (struct usbctlx_cmd_completor *)head; 636 - return usbctlx_get_status(complete->cmdresp, complete->result); 637 - } 638 - 639 - static inline struct usbctlx_completor * 640 - init_cmd_completor(struct usbctlx_cmd_completor *completor, 641 - const struct hfa384x_usb_statusresp *cmdresp, 642 - struct hfa384x_cmdresult *result) 643 - { 644 - completor->head.complete = usbctlx_cmd_completor_fn; 645 - completor->cmdresp = cmdresp; 646 - completor->result = result; 647 - return &completor->head; 648 - } 649 - 650 - /*---------------------------------------------------------------- 651 - * Completor object: 652 - * This completor must be passed to hfa384x_usbctlx_complete_sync() 653 - * when processing a CTLX that reads a RID. 654 - *---------------------------------------------------------------- 655 - */ 656 - struct usbctlx_rrid_completor { 657 - struct usbctlx_completor head; 658 - 659 - const struct hfa384x_usb_rridresp *rridresp; 660 - void *riddata; 661 - unsigned int riddatalen; 662 - }; 663 - 664 - static int usbctlx_rrid_completor_fn(struct usbctlx_completor *head) 665 - { 666 - struct usbctlx_rrid_completor *complete; 667 - struct hfa384x_rridresult rridresult; 668 - 669 - complete = (struct usbctlx_rrid_completor *)head; 670 - usbctlx_get_rridresult(complete->rridresp, &rridresult); 671 - 672 - /* Validate the length, note body len calculation in bytes */ 673 - if (rridresult.riddata_len != complete->riddatalen) { 674 - pr_warn("RID len mismatch, rid=0x%04x hlen=%d fwlen=%d\n", 675 - rridresult.rid, 676 - complete->riddatalen, rridresult.riddata_len); 677 - return -ENODATA; 678 - } 679 - 680 - memcpy(complete->riddata, rridresult.riddata, complete->riddatalen); 681 - return 0; 682 - } 683 - 684 - static inline struct usbctlx_completor * 685 - init_rrid_completor(struct usbctlx_rrid_completor *completor, 686 - const struct hfa384x_usb_rridresp *rridresp, 687 - void *riddata, 688 - unsigned int riddatalen) 689 - { 690 - completor->head.complete = usbctlx_rrid_completor_fn; 691 - completor->rridresp = rridresp; 692 - completor->riddata = riddata; 693 - completor->riddatalen = riddatalen; 694 - return &completor->head; 695 - } 696 - 697 - /*---------------------------------------------------------------- 698 - * Completor object: 699 - * Interprets the results of a synchronous RID-write 700 - *---------------------------------------------------------------- 701 - */ 702 - #define init_wrid_completor init_cmd_completor 703 - 704 - /*---------------------------------------------------------------- 705 - * Completor object: 706 - * Interprets the results of a synchronous memory-write 707 - *---------------------------------------------------------------- 708 - */ 709 - #define init_wmem_completor init_cmd_completor 710 - 711 - /*---------------------------------------------------------------- 712 - * Completor object: 713 - * Interprets the results of a synchronous memory-read 714 - *---------------------------------------------------------------- 715 - */ 716 - struct usbctlx_rmem_completor { 717 - struct usbctlx_completor head; 718 - 719 - const struct hfa384x_usb_rmemresp *rmemresp; 720 - void *data; 721 - unsigned int len; 722 - }; 723 - 724 - static int usbctlx_rmem_completor_fn(struct usbctlx_completor *head) 725 - { 726 - struct usbctlx_rmem_completor *complete = 727 - (struct usbctlx_rmem_completor *)head; 728 - 729 - pr_debug("rmemresp:len=%d\n", complete->rmemresp->frmlen); 730 - memcpy(complete->data, complete->rmemresp->data, complete->len); 731 - return 0; 732 - } 733 - 734 - static inline struct usbctlx_completor * 735 - init_rmem_completor(struct usbctlx_rmem_completor *completor, 736 - struct hfa384x_usb_rmemresp *rmemresp, 737 - void *data, 738 - unsigned int len) 739 - { 740 - completor->head.complete = usbctlx_rmem_completor_fn; 741 - completor->rmemresp = rmemresp; 742 - completor->data = data; 743 - completor->len = len; 744 - return &completor->head; 745 - } 746 - 747 - /*---------------------------------------------------------------- 748 - * hfa384x_cb_status 749 - * 750 - * Ctlx_complete handler for async CMD type control exchanges. 751 - * mark the hw struct as such. 752 - * 753 - * Note: If the handling is changed here, it should probably be 754 - * changed in docmd as well. 755 - * 756 - * Arguments: 757 - * hw hw struct 758 - * ctlx completed CTLX 759 - * 760 - * Returns: 761 - * nothing 762 - * 763 - * Side effects: 764 - * 765 - * Call context: 766 - * interrupt 767 - *---------------------------------------------------------------- 768 - */ 769 - static void hfa384x_cb_status(struct hfa384x *hw, 770 - const struct hfa384x_usbctlx *ctlx) 771 - { 772 - if (ctlx->usercb) { 773 - struct hfa384x_cmdresult cmdresult; 774 - 775 - if (ctlx->state != CTLX_COMPLETE) { 776 - memset(&cmdresult, 0, sizeof(cmdresult)); 777 - cmdresult.status = 778 - HFA384x_STATUS_RESULT_SET(HFA384x_CMD_ERR); 779 - } else { 780 - usbctlx_get_status(&ctlx->inbuf.cmdresp, &cmdresult); 781 - } 782 - 783 - ctlx->usercb(hw, &cmdresult, ctlx->usercb_data); 784 - } 785 - } 786 - 787 - /*---------------------------------------------------------------- 788 - * hfa384x_cmd_initialize 789 - * 790 - * Issues the initialize command and sets the hw->state based 791 - * on the result. 792 - * 793 - * Arguments: 794 - * hw device structure 795 - * 796 - * Returns: 797 - * 0 success 798 - * >0 f/w reported error - f/w status code 799 - * <0 driver reported error 800 - * 801 - * Side effects: 802 - * 803 - * Call context: 804 - * process 805 - *---------------------------------------------------------------- 806 - */ 807 - int hfa384x_cmd_initialize(struct hfa384x *hw) 808 - { 809 - int result = 0; 810 - int i; 811 - struct hfa384x_metacmd cmd; 812 - 813 - cmd.cmd = HFA384x_CMDCODE_INIT; 814 - cmd.parm0 = 0; 815 - cmd.parm1 = 0; 816 - cmd.parm2 = 0; 817 - 818 - result = hfa384x_docmd(hw, &cmd); 819 - 820 - pr_debug("cmdresp.init: status=0x%04x, resp0=0x%04x, resp1=0x%04x, resp2=0x%04x\n", 821 - cmd.result.status, 822 - cmd.result.resp0, cmd.result.resp1, cmd.result.resp2); 823 - if (result == 0) { 824 - for (i = 0; i < HFA384x_NUMPORTS_MAX; i++) 825 - hw->port_enabled[i] = 0; 826 - } 827 - 828 - hw->link_status = HFA384x_LINK_NOTCONNECTED; 829 - 830 - return result; 831 - } 832 - 833 - /*---------------------------------------------------------------- 834 - * hfa384x_cmd_disable 835 - * 836 - * Issues the disable command to stop communications on one of 837 - * the MACs 'ports'. 838 - * 839 - * Arguments: 840 - * hw device structure 841 - * macport MAC port number (host order) 842 - * 843 - * Returns: 844 - * 0 success 845 - * >0 f/w reported failure - f/w status code 846 - * <0 driver reported error (timeout|bad arg) 847 - * 848 - * Side effects: 849 - * 850 - * Call context: 851 - * process 852 - *---------------------------------------------------------------- 853 - */ 854 - int hfa384x_cmd_disable(struct hfa384x *hw, u16 macport) 855 - { 856 - struct hfa384x_metacmd cmd; 857 - 858 - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DISABLE) | 859 - HFA384x_CMD_MACPORT_SET(macport); 860 - cmd.parm0 = 0; 861 - cmd.parm1 = 0; 862 - cmd.parm2 = 0; 863 - 864 - return hfa384x_docmd(hw, &cmd); 865 - } 866 - 867 - /*---------------------------------------------------------------- 868 - * hfa384x_cmd_enable 869 - * 870 - * Issues the enable command to enable communications on one of 871 - * the MACs 'ports'. 872 - * 873 - * Arguments: 874 - * hw device structure 875 - * macport MAC port number 876 - * 877 - * Returns: 878 - * 0 success 879 - * >0 f/w reported failure - f/w status code 880 - * <0 driver reported error (timeout|bad arg) 881 - * 882 - * Side effects: 883 - * 884 - * Call context: 885 - * process 886 - *---------------------------------------------------------------- 887 - */ 888 - int hfa384x_cmd_enable(struct hfa384x *hw, u16 macport) 889 - { 890 - struct hfa384x_metacmd cmd; 891 - 892 - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_ENABLE) | 893 - HFA384x_CMD_MACPORT_SET(macport); 894 - cmd.parm0 = 0; 895 - cmd.parm1 = 0; 896 - cmd.parm2 = 0; 897 - 898 - return hfa384x_docmd(hw, &cmd); 899 - } 900 - 901 - /*---------------------------------------------------------------- 902 - * hfa384x_cmd_monitor 903 - * 904 - * Enables the 'monitor mode' of the MAC. Here's the description of 905 - * monitor mode that I've received thus far: 906 - * 907 - * "The "monitor mode" of operation is that the MAC passes all 908 - * frames for which the PLCP checks are correct. All received 909 - * MPDUs are passed to the host with MAC Port = 7, with a 910 - * receive status of good, FCS error, or undecryptable. Passing 911 - * certain MPDUs is a violation of the 802.11 standard, but useful 912 - * for a debugging tool." Normal communication is not possible 913 - * while monitor mode is enabled. 914 - * 915 - * Arguments: 916 - * hw device structure 917 - * enable a code (0x0b|0x0f) that enables/disables 918 - * monitor mode. (host order) 919 - * 920 - * Returns: 921 - * 0 success 922 - * >0 f/w reported failure - f/w status code 923 - * <0 driver reported error (timeout|bad arg) 924 - * 925 - * Side effects: 926 - * 927 - * Call context: 928 - * process 929 - *---------------------------------------------------------------- 930 - */ 931 - int hfa384x_cmd_monitor(struct hfa384x *hw, u16 enable) 932 - { 933 - struct hfa384x_metacmd cmd; 934 - 935 - cmd.cmd = HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_MONITOR) | 936 - HFA384x_CMD_AINFO_SET(enable); 937 - cmd.parm0 = 0; 938 - cmd.parm1 = 0; 939 - cmd.parm2 = 0; 940 - 941 - return hfa384x_docmd(hw, &cmd); 942 - } 943 - 944 - /*---------------------------------------------------------------- 945 - * hfa384x_cmd_download 946 - * 947 - * Sets the controls for the MAC controller code/data download 948 - * process. The arguments set the mode and address associated 949 - * with a download. Note that the aux registers should be enabled 950 - * prior to setting one of the download enable modes. 951 - * 952 - * Arguments: 953 - * hw device structure 954 - * mode 0 - Disable programming and begin code exec 955 - * 1 - Enable volatile mem programming 956 - * 2 - Enable non-volatile mem programming 957 - * 3 - Program non-volatile section from NV download 958 - * buffer. 959 - * (host order) 960 - * lowaddr 961 - * highaddr For mode 1, sets the high & low order bits of 962 - * the "destination address". This address will be 963 - * the execution start address when download is 964 - * subsequently disabled. 965 - * For mode 2, sets the high & low order bits of 966 - * the destination in NV ram. 967 - * For modes 0 & 3, should be zero. (host order) 968 - * NOTE: these are CMD format. 969 - * codelen Length of the data to write in mode 2, 970 - * zero otherwise. (host order) 971 - * 972 - * Returns: 973 - * 0 success 974 - * >0 f/w reported failure - f/w status code 975 - * <0 driver reported error (timeout|bad arg) 976 - * 977 - * Side effects: 978 - * 979 - * Call context: 980 - * process 981 - *---------------------------------------------------------------- 982 - */ 983 - int hfa384x_cmd_download(struct hfa384x *hw, u16 mode, u16 lowaddr, 984 - u16 highaddr, u16 codelen) 985 - { 986 - struct hfa384x_metacmd cmd; 987 - 988 - pr_debug("mode=%d, lowaddr=0x%04x, highaddr=0x%04x, codelen=%d\n", 989 - mode, lowaddr, highaddr, codelen); 990 - 991 - cmd.cmd = (HFA384x_CMD_CMDCODE_SET(HFA384x_CMDCODE_DOWNLD) | 992 - HFA384x_CMD_PROGMODE_SET(mode)); 993 - 994 - cmd.parm0 = lowaddr; 995 - cmd.parm1 = highaddr; 996 - cmd.parm2 = codelen; 997 - 998 - return hfa384x_docmd(hw, &cmd); 999 - } 1000 - 1001 - /*---------------------------------------------------------------- 1002 - * hfa384x_corereset 1003 - * 1004 - * Perform a reset of the hfa38xx MAC core. We assume that the hw 1005 - * structure is in its "created" state. That is, it is initialized 1006 - * with proper values. Note that if a reset is done after the 1007 - * device has been active for awhile, the caller might have to clean 1008 - * up some leftover cruft in the hw structure. 1009 - * 1010 - * Arguments: 1011 - * hw device structure 1012 - * holdtime how long (in ms) to hold the reset 1013 - * settletime how long (in ms) to wait after releasing 1014 - * the reset 1015 - * 1016 - * Returns: 1017 - * nothing 1018 - * 1019 - * Side effects: 1020 - * 1021 - * Call context: 1022 - * process 1023 - *---------------------------------------------------------------- 1024 - */ 1025 - int hfa384x_corereset(struct hfa384x *hw, int holdtime, 1026 - int settletime, int genesis) 1027 - { 1028 - int result; 1029 - 1030 - result = usb_reset_device(hw->usb); 1031 - if (result < 0) { 1032 - netdev_err(hw->wlandev->netdev, "usb_reset_device() failed, result=%d.\n", 1033 - result); 1034 - } 1035 - 1036 - return result; 1037 - } 1038 - 1039 - /*---------------------------------------------------------------- 1040 - * hfa384x_usbctlx_complete_sync 1041 - * 1042 - * Waits for a synchronous CTLX object to complete, 1043 - * and then handles the response. 1044 - * 1045 - * Arguments: 1046 - * hw device structure 1047 - * ctlx CTLX ptr 1048 - * completor functor object to decide what to 1049 - * do with the CTLX's result. 1050 - * 1051 - * Returns: 1052 - * 0 Success 1053 - * -ERESTARTSYS Interrupted by a signal 1054 - * -EIO CTLX failed 1055 - * -ENODEV Adapter was unplugged 1056 - * ??? Result from completor 1057 - * 1058 - * Side effects: 1059 - * 1060 - * Call context: 1061 - * process 1062 - *---------------------------------------------------------------- 1063 - */ 1064 - static int hfa384x_usbctlx_complete_sync(struct hfa384x *hw, 1065 - struct hfa384x_usbctlx *ctlx, 1066 - struct usbctlx_completor *completor) 1067 - { 1068 - unsigned long flags; 1069 - int result; 1070 - 1071 - result = wait_for_completion_interruptible(&ctlx->done); 1072 - 1073 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 1074 - 1075 - /* 1076 - * We can only handle the CTLX if the USB disconnect 1077 - * function has not run yet ... 1078 - */ 1079 - cleanup: 1080 - if (hw->wlandev->hwremoved) { 1081 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 1082 - result = -ENODEV; 1083 - } else if (result != 0) { 1084 - int runqueue = 0; 1085 - 1086 - /* 1087 - * We were probably interrupted, so delete 1088 - * this CTLX asynchronously, kill the timers 1089 - * and the URB, and then start the next 1090 - * pending CTLX. 1091 - * 1092 - * NOTE: We can only delete the timers and 1093 - * the URB if this CTLX is active. 1094 - */ 1095 - if (ctlx == get_active_ctlx(hw)) { 1096 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 1097 - 1098 - del_timer_sync(&hw->reqtimer); 1099 - del_timer_sync(&hw->resptimer); 1100 - hw->req_timer_done = 1; 1101 - hw->resp_timer_done = 1; 1102 - usb_kill_urb(&hw->ctlx_urb); 1103 - 1104 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 1105 - 1106 - runqueue = 1; 1107 - 1108 - /* 1109 - * This scenario is so unlikely that I'm 1110 - * happy with a grubby "goto" solution ... 1111 - */ 1112 - if (hw->wlandev->hwremoved) 1113 - goto cleanup; 1114 - } 1115 - 1116 - /* 1117 - * The completion task will send this CTLX 1118 - * to the reaper the next time it runs. We 1119 - * are no longer in a hurry. 1120 - */ 1121 - ctlx->reapable = 1; 1122 - ctlx->state = CTLX_REQ_FAILED; 1123 - list_move_tail(&ctlx->list, &hw->ctlxq.completing); 1124 - 1125 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 1126 - 1127 - if (runqueue) 1128 - hfa384x_usbctlxq_run(hw); 1129 - } else { 1130 - if (ctlx->state == CTLX_COMPLETE) { 1131 - result = completor->complete(completor); 1132 - } else { 1133 - netdev_warn(hw->wlandev->netdev, "CTLX[%d] error: state(%s)\n", 1134 - le16_to_cpu(ctlx->outbuf.type), 1135 - ctlxstr(ctlx->state)); 1136 - result = -EIO; 1137 - } 1138 - 1139 - list_del(&ctlx->list); 1140 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 1141 - kfree(ctlx); 1142 - } 1143 - 1144 - return result; 1145 - } 1146 - 1147 - /*---------------------------------------------------------------- 1148 - * hfa384x_docmd 1149 - * 1150 - * Constructs a command CTLX and submits it. 1151 - * 1152 - * NOTE: Any changes to the 'post-submit' code in this function 1153 - * need to be carried over to hfa384x_cbcmd() since the handling 1154 - * is virtually identical. 1155 - * 1156 - * Arguments: 1157 - * hw device structure 1158 - * cmd cmd structure. Includes all arguments and result 1159 - * data points. All in host order. in host order 1160 - * 1161 - * Returns: 1162 - * 0 success 1163 - * -EIO CTLX failure 1164 - * -ERESTARTSYS Awakened on signal 1165 - * >0 command indicated error, Status and Resp0-2 are 1166 - * in hw structure. 1167 - * 1168 - * Side effects: 1169 - * 1170 - * 1171 - * Call context: 1172 - * process 1173 - *---------------------------------------------------------------- 1174 - */ 1175 - static inline int 1176 - hfa384x_docmd(struct hfa384x *hw, 1177 - struct hfa384x_metacmd *cmd) 1178 - { 1179 - int result; 1180 - struct hfa384x_usbctlx *ctlx; 1181 - 1182 - ctlx = usbctlx_alloc(); 1183 - if (!ctlx) { 1184 - result = -ENOMEM; 1185 - goto done; 1186 - } 1187 - 1188 - /* Initialize the command */ 1189 - ctlx->outbuf.cmdreq.type = cpu_to_le16(HFA384x_USB_CMDREQ); 1190 - ctlx->outbuf.cmdreq.cmd = cpu_to_le16(cmd->cmd); 1191 - ctlx->outbuf.cmdreq.parm0 = cpu_to_le16(cmd->parm0); 1192 - ctlx->outbuf.cmdreq.parm1 = cpu_to_le16(cmd->parm1); 1193 - ctlx->outbuf.cmdreq.parm2 = cpu_to_le16(cmd->parm2); 1194 - 1195 - ctlx->outbufsize = sizeof(ctlx->outbuf.cmdreq); 1196 - 1197 - pr_debug("cmdreq: cmd=0x%04x parm0=0x%04x parm1=0x%04x parm2=0x%04x\n", 1198 - cmd->cmd, cmd->parm0, cmd->parm1, cmd->parm2); 1199 - 1200 - ctlx->reapable = DOWAIT; 1201 - ctlx->cmdcb = NULL; 1202 - ctlx->usercb = NULL; 1203 - ctlx->usercb_data = NULL; 1204 - 1205 - result = hfa384x_usbctlx_submit(hw, ctlx); 1206 - if (result != 0) { 1207 - kfree(ctlx); 1208 - } else { 1209 - struct usbctlx_cmd_completor cmd_completor; 1210 - struct usbctlx_completor *completor; 1211 - 1212 - completor = init_cmd_completor(&cmd_completor, 1213 - &ctlx->inbuf.cmdresp, 1214 - &cmd->result); 1215 - 1216 - result = hfa384x_usbctlx_complete_sync(hw, ctlx, completor); 1217 - } 1218 - 1219 - done: 1220 - return result; 1221 - } 1222 - 1223 - /*---------------------------------------------------------------- 1224 - * hfa384x_dorrid 1225 - * 1226 - * Constructs a read rid CTLX and issues it. 1227 - * 1228 - * NOTE: Any changes to the 'post-submit' code in this function 1229 - * need to be carried over to hfa384x_cbrrid() since the handling 1230 - * is virtually identical. 1231 - * 1232 - * Arguments: 1233 - * hw device structure 1234 - * mode DOWAIT or DOASYNC 1235 - * rid Read RID number (host order) 1236 - * riddata Caller supplied buffer that MAC formatted RID.data 1237 - * record will be written to for DOWAIT calls. Should 1238 - * be NULL for DOASYNC calls. 1239 - * riddatalen Buffer length for DOWAIT calls. Zero for DOASYNC calls. 1240 - * cmdcb command callback for async calls, NULL for DOWAIT calls 1241 - * usercb user callback for async calls, NULL for DOWAIT calls 1242 - * usercb_data user supplied data pointer for async calls, NULL 1243 - * for DOWAIT calls 1244 - * 1245 - * Returns: 1246 - * 0 success 1247 - * -EIO CTLX failure 1248 - * -ERESTARTSYS Awakened on signal 1249 - * -ENODATA riddatalen != macdatalen 1250 - * >0 command indicated error, Status and Resp0-2 are 1251 - * in hw structure. 1252 - * 1253 - * Side effects: 1254 - * 1255 - * Call context: 1256 - * interrupt (DOASYNC) 1257 - * process (DOWAIT or DOASYNC) 1258 - *---------------------------------------------------------------- 1259 - */ 1260 - static int 1261 - hfa384x_dorrid(struct hfa384x *hw, 1262 - enum cmd_mode mode, 1263 - u16 rid, 1264 - void *riddata, 1265 - unsigned int riddatalen, 1266 - ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) 1267 - { 1268 - int result; 1269 - struct hfa384x_usbctlx *ctlx; 1270 - 1271 - ctlx = usbctlx_alloc(); 1272 - if (!ctlx) { 1273 - result = -ENOMEM; 1274 - goto done; 1275 - } 1276 - 1277 - /* Initialize the command */ 1278 - ctlx->outbuf.rridreq.type = cpu_to_le16(HFA384x_USB_RRIDREQ); 1279 - ctlx->outbuf.rridreq.frmlen = 1280 - cpu_to_le16(sizeof(ctlx->outbuf.rridreq.rid)); 1281 - ctlx->outbuf.rridreq.rid = cpu_to_le16(rid); 1282 - 1283 - ctlx->outbufsize = sizeof(ctlx->outbuf.rridreq); 1284 - 1285 - ctlx->reapable = mode; 1286 - ctlx->cmdcb = cmdcb; 1287 - ctlx->usercb = usercb; 1288 - ctlx->usercb_data = usercb_data; 1289 - 1290 - /* Submit the CTLX */ 1291 - result = hfa384x_usbctlx_submit(hw, ctlx); 1292 - if (result != 0) { 1293 - kfree(ctlx); 1294 - } else if (mode == DOWAIT) { 1295 - struct usbctlx_rrid_completor completor; 1296 - 1297 - result = 1298 - hfa384x_usbctlx_complete_sync(hw, ctlx, 1299 - init_rrid_completor 1300 - (&completor, 1301 - &ctlx->inbuf.rridresp, 1302 - riddata, riddatalen)); 1303 - } 1304 - 1305 - done: 1306 - return result; 1307 - } 1308 - 1309 - /*---------------------------------------------------------------- 1310 - * hfa384x_dowrid 1311 - * 1312 - * Constructs a write rid CTLX and issues it. 1313 - * 1314 - * NOTE: Any changes to the 'post-submit' code in this function 1315 - * need to be carried over to hfa384x_cbwrid() since the handling 1316 - * is virtually identical. 1317 - * 1318 - * Arguments: 1319 - * hw device structure 1320 - * enum cmd_mode DOWAIT or DOASYNC 1321 - * rid RID code 1322 - * riddata Data portion of RID formatted for MAC 1323 - * riddatalen Length of the data portion in bytes 1324 - * cmdcb command callback for async calls, NULL for DOWAIT calls 1325 - * usercb user callback for async calls, NULL for DOWAIT calls 1326 - * usercb_data user supplied data pointer for async calls 1327 - * 1328 - * Returns: 1329 - * 0 success 1330 - * -ETIMEDOUT timed out waiting for register ready or 1331 - * command completion 1332 - * >0 command indicated error, Status and Resp0-2 are 1333 - * in hw structure. 1334 - * 1335 - * Side effects: 1336 - * 1337 - * Call context: 1338 - * interrupt (DOASYNC) 1339 - * process (DOWAIT or DOASYNC) 1340 - *---------------------------------------------------------------- 1341 - */ 1342 - static int 1343 - hfa384x_dowrid(struct hfa384x *hw, 1344 - enum cmd_mode mode, 1345 - u16 rid, 1346 - void *riddata, 1347 - unsigned int riddatalen, 1348 - ctlx_cmdcb_t cmdcb, ctlx_usercb_t usercb, void *usercb_data) 1349 - { 1350 - int result; 1351 - struct hfa384x_usbctlx *ctlx; 1352 - 1353 - ctlx = usbctlx_alloc(); 1354 - if (!ctlx) { 1355 - result = -ENOMEM; 1356 - goto done; 1357 - } 1358 - 1359 - /* Initialize the command */ 1360 - ctlx->outbuf.wridreq.type = cpu_to_le16(HFA384x_USB_WRIDREQ); 1361 - ctlx->outbuf.wridreq.frmlen = cpu_to_le16((sizeof 1362 - (ctlx->outbuf.wridreq.rid) + 1363 - riddatalen + 1) / 2); 1364 - ctlx->outbuf.wridreq.rid = cpu_to_le16(rid); 1365 - memcpy(ctlx->outbuf.wridreq.data, riddata, riddatalen); 1366 - 1367 - ctlx->outbufsize = sizeof(ctlx->outbuf.wridreq.type) + 1368 - sizeof(ctlx->outbuf.wridreq.frmlen) + 1369 - sizeof(ctlx->outbuf.wridreq.rid) + riddatalen; 1370 - 1371 - ctlx->reapable = mode; 1372 - ctlx->cmdcb = cmdcb; 1373 - ctlx->usercb = usercb; 1374 - ctlx->usercb_data = usercb_data; 1375 - 1376 - /* Submit the CTLX */ 1377 - result = hfa384x_usbctlx_submit(hw, ctlx); 1378 - if (result != 0) { 1379 - kfree(ctlx); 1380 - } else if (mode == DOWAIT) { 1381 - struct usbctlx_cmd_completor completor; 1382 - struct hfa384x_cmdresult wridresult; 1383 - 1384 - result = hfa384x_usbctlx_complete_sync(hw, 1385 - ctlx, 1386 - init_wrid_completor 1387 - (&completor, 1388 - &ctlx->inbuf.wridresp, 1389 - &wridresult)); 1390 - } 1391 - 1392 - done: 1393 - return result; 1394 - } 1395 - 1396 - /*---------------------------------------------------------------- 1397 - * hfa384x_dormem 1398 - * 1399 - * Constructs a readmem CTLX and issues it. 1400 - * 1401 - * NOTE: Any changes to the 'post-submit' code in this function 1402 - * need to be carried over to hfa384x_cbrmem() since the handling 1403 - * is virtually identical. 1404 - * 1405 - * Arguments: 1406 - * hw device structure 1407 - * page MAC address space page (CMD format) 1408 - * offset MAC address space offset 1409 - * data Ptr to data buffer to receive read 1410 - * len Length of the data to read (max == 2048) 1411 - * 1412 - * Returns: 1413 - * 0 success 1414 - * -ETIMEDOUT timed out waiting for register ready or 1415 - * command completion 1416 - * >0 command indicated error, Status and Resp0-2 are 1417 - * in hw structure. 1418 - * 1419 - * Side effects: 1420 - * 1421 - * Call context: 1422 - * process (DOWAIT) 1423 - *---------------------------------------------------------------- 1424 - */ 1425 - static int 1426 - hfa384x_dormem(struct hfa384x *hw, 1427 - u16 page, 1428 - u16 offset, 1429 - void *data, 1430 - unsigned int len) 1431 - { 1432 - int result; 1433 - struct hfa384x_usbctlx *ctlx; 1434 - 1435 - ctlx = usbctlx_alloc(); 1436 - if (!ctlx) { 1437 - result = -ENOMEM; 1438 - goto done; 1439 - } 1440 - 1441 - /* Initialize the command */ 1442 - ctlx->outbuf.rmemreq.type = cpu_to_le16(HFA384x_USB_RMEMREQ); 1443 - ctlx->outbuf.rmemreq.frmlen = 1444 - cpu_to_le16(sizeof(ctlx->outbuf.rmemreq.offset) + 1445 - sizeof(ctlx->outbuf.rmemreq.page) + len); 1446 - ctlx->outbuf.rmemreq.offset = cpu_to_le16(offset); 1447 - ctlx->outbuf.rmemreq.page = cpu_to_le16(page); 1448 - 1449 - ctlx->outbufsize = sizeof(ctlx->outbuf.rmemreq); 1450 - 1451 - pr_debug("type=0x%04x frmlen=%d offset=0x%04x page=0x%04x\n", 1452 - ctlx->outbuf.rmemreq.type, 1453 - ctlx->outbuf.rmemreq.frmlen, 1454 - ctlx->outbuf.rmemreq.offset, ctlx->outbuf.rmemreq.page); 1455 - 1456 - pr_debug("pktsize=%zd\n", ROUNDUP64(sizeof(ctlx->outbuf.rmemreq))); 1457 - 1458 - ctlx->reapable = DOWAIT; 1459 - ctlx->cmdcb = NULL; 1460 - ctlx->usercb = NULL; 1461 - ctlx->usercb_data = NULL; 1462 - 1463 - result = hfa384x_usbctlx_submit(hw, ctlx); 1464 - if (result != 0) { 1465 - kfree(ctlx); 1466 - } else { 1467 - struct usbctlx_rmem_completor completor; 1468 - 1469 - result = 1470 - hfa384x_usbctlx_complete_sync(hw, ctlx, 1471 - init_rmem_completor 1472 - (&completor, 1473 - &ctlx->inbuf.rmemresp, data, 1474 - len)); 1475 - } 1476 - 1477 - done: 1478 - return result; 1479 - } 1480 - 1481 - /*---------------------------------------------------------------- 1482 - * hfa384x_dowmem 1483 - * 1484 - * Constructs a writemem CTLX and issues it. 1485 - * 1486 - * NOTE: Any changes to the 'post-submit' code in this function 1487 - * need to be carried over to hfa384x_cbwmem() since the handling 1488 - * is virtually identical. 1489 - * 1490 - * Arguments: 1491 - * hw device structure 1492 - * page MAC address space page (CMD format) 1493 - * offset MAC address space offset 1494 - * data Ptr to data buffer containing write data 1495 - * len Length of the data to read (max == 2048) 1496 - * 1497 - * Returns: 1498 - * 0 success 1499 - * -ETIMEDOUT timed out waiting for register ready or 1500 - * command completion 1501 - * >0 command indicated error, Status and Resp0-2 are 1502 - * in hw structure. 1503 - * 1504 - * Side effects: 1505 - * 1506 - * Call context: 1507 - * interrupt (DOWAIT) 1508 - * process (DOWAIT) 1509 - *---------------------------------------------------------------- 1510 - */ 1511 - static int 1512 - hfa384x_dowmem(struct hfa384x *hw, 1513 - u16 page, 1514 - u16 offset, 1515 - void *data, 1516 - unsigned int len) 1517 - { 1518 - int result; 1519 - struct hfa384x_usbctlx *ctlx; 1520 - 1521 - pr_debug("page=0x%04x offset=0x%04x len=%d\n", page, offset, len); 1522 - 1523 - ctlx = usbctlx_alloc(); 1524 - if (!ctlx) { 1525 - result = -ENOMEM; 1526 - goto done; 1527 - } 1528 - 1529 - /* Initialize the command */ 1530 - ctlx->outbuf.wmemreq.type = cpu_to_le16(HFA384x_USB_WMEMREQ); 1531 - ctlx->outbuf.wmemreq.frmlen = 1532 - cpu_to_le16(sizeof(ctlx->outbuf.wmemreq.offset) + 1533 - sizeof(ctlx->outbuf.wmemreq.page) + len); 1534 - ctlx->outbuf.wmemreq.offset = cpu_to_le16(offset); 1535 - ctlx->outbuf.wmemreq.page = cpu_to_le16(page); 1536 - memcpy(ctlx->outbuf.wmemreq.data, data, len); 1537 - 1538 - ctlx->outbufsize = sizeof(ctlx->outbuf.wmemreq.type) + 1539 - sizeof(ctlx->outbuf.wmemreq.frmlen) + 1540 - sizeof(ctlx->outbuf.wmemreq.offset) + 1541 - sizeof(ctlx->outbuf.wmemreq.page) + len; 1542 - 1543 - ctlx->reapable = DOWAIT; 1544 - ctlx->cmdcb = NULL; 1545 - ctlx->usercb = NULL; 1546 - ctlx->usercb_data = NULL; 1547 - 1548 - result = hfa384x_usbctlx_submit(hw, ctlx); 1549 - if (result != 0) { 1550 - kfree(ctlx); 1551 - } else { 1552 - struct usbctlx_cmd_completor completor; 1553 - struct hfa384x_cmdresult wmemresult; 1554 - 1555 - result = hfa384x_usbctlx_complete_sync(hw, 1556 - ctlx, 1557 - init_wmem_completor 1558 - (&completor, 1559 - &ctlx->inbuf.wmemresp, 1560 - &wmemresult)); 1561 - } 1562 - 1563 - done: 1564 - return result; 1565 - } 1566 - 1567 - /*---------------------------------------------------------------- 1568 - * hfa384x_drvr_disable 1569 - * 1570 - * Issues the disable command to stop communications on one of 1571 - * the MACs 'ports'. Only macport 0 is valid for stations. 1572 - * APs may also disable macports 1-6. Only ports that have been 1573 - * previously enabled may be disabled. 1574 - * 1575 - * Arguments: 1576 - * hw device structure 1577 - * macport MAC port number (host order) 1578 - * 1579 - * Returns: 1580 - * 0 success 1581 - * >0 f/w reported failure - f/w status code 1582 - * <0 driver reported error (timeout|bad arg) 1583 - * 1584 - * Side effects: 1585 - * 1586 - * Call context: 1587 - * process 1588 - *---------------------------------------------------------------- 1589 - */ 1590 - int hfa384x_drvr_disable(struct hfa384x *hw, u16 macport) 1591 - { 1592 - int result = 0; 1593 - 1594 - if ((!hw->isap && macport != 0) || 1595 - (hw->isap && !(macport <= HFA384x_PORTID_MAX)) || 1596 - !(hw->port_enabled[macport])) { 1597 - result = -EINVAL; 1598 - } else { 1599 - result = hfa384x_cmd_disable(hw, macport); 1600 - if (result == 0) 1601 - hw->port_enabled[macport] = 0; 1602 - } 1603 - return result; 1604 - } 1605 - 1606 - /*---------------------------------------------------------------- 1607 - * hfa384x_drvr_enable 1608 - * 1609 - * Issues the enable command to enable communications on one of 1610 - * the MACs 'ports'. Only macport 0 is valid for stations. 1611 - * APs may also enable macports 1-6. Only ports that are currently 1612 - * disabled may be enabled. 1613 - * 1614 - * Arguments: 1615 - * hw device structure 1616 - * macport MAC port number 1617 - * 1618 - * Returns: 1619 - * 0 success 1620 - * >0 f/w reported failure - f/w status code 1621 - * <0 driver reported error (timeout|bad arg) 1622 - * 1623 - * Side effects: 1624 - * 1625 - * Call context: 1626 - * process 1627 - *---------------------------------------------------------------- 1628 - */ 1629 - int hfa384x_drvr_enable(struct hfa384x *hw, u16 macport) 1630 - { 1631 - int result = 0; 1632 - 1633 - if ((!hw->isap && macport != 0) || 1634 - (hw->isap && !(macport <= HFA384x_PORTID_MAX)) || 1635 - (hw->port_enabled[macport])) { 1636 - result = -EINVAL; 1637 - } else { 1638 - result = hfa384x_cmd_enable(hw, macport); 1639 - if (result == 0) 1640 - hw->port_enabled[macport] = 1; 1641 - } 1642 - return result; 1643 - } 1644 - 1645 - /*---------------------------------------------------------------- 1646 - * hfa384x_drvr_flashdl_enable 1647 - * 1648 - * Begins the flash download state. Checks to see that we're not 1649 - * already in a download state and that a port isn't enabled. 1650 - * Sets the download state and retrieves the flash download 1651 - * buffer location, buffer size, and timeout length. 1652 - * 1653 - * Arguments: 1654 - * hw device structure 1655 - * 1656 - * Returns: 1657 - * 0 success 1658 - * >0 f/w reported error - f/w status code 1659 - * <0 driver reported error 1660 - * 1661 - * Side effects: 1662 - * 1663 - * Call context: 1664 - * process 1665 - *---------------------------------------------------------------- 1666 - */ 1667 - int hfa384x_drvr_flashdl_enable(struct hfa384x *hw) 1668 - { 1669 - int result = 0; 1670 - int i; 1671 - 1672 - /* Check that a port isn't active */ 1673 - for (i = 0; i < HFA384x_PORTID_MAX; i++) { 1674 - if (hw->port_enabled[i]) { 1675 - pr_debug("called when port enabled.\n"); 1676 - return -EINVAL; 1677 - } 1678 - } 1679 - 1680 - /* Check that we're not already in a download state */ 1681 - if (hw->dlstate != HFA384x_DLSTATE_DISABLED) 1682 - return -EINVAL; 1683 - 1684 - /* Retrieve the buffer loc&size and timeout */ 1685 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DOWNLOADBUFFER, 1686 - &hw->bufinfo, sizeof(hw->bufinfo)); 1687 - if (result) 1688 - return result; 1689 - 1690 - le16_to_cpus(&hw->bufinfo.page); 1691 - le16_to_cpus(&hw->bufinfo.offset); 1692 - le16_to_cpus(&hw->bufinfo.len); 1693 - result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_MAXLOADTIME, 1694 - &hw->dltimeout); 1695 - if (result) 1696 - return result; 1697 - 1698 - le16_to_cpus(&hw->dltimeout); 1699 - 1700 - pr_debug("flashdl_enable\n"); 1701 - 1702 - hw->dlstate = HFA384x_DLSTATE_FLASHENABLED; 1703 - 1704 - return result; 1705 - } 1706 - 1707 - /*---------------------------------------------------------------- 1708 - * hfa384x_drvr_flashdl_disable 1709 - * 1710 - * Ends the flash download state. Note that this will cause the MAC 1711 - * firmware to restart. 1712 - * 1713 - * Arguments: 1714 - * hw device structure 1715 - * 1716 - * Returns: 1717 - * 0 success 1718 - * >0 f/w reported error - f/w status code 1719 - * <0 driver reported error 1720 - * 1721 - * Side effects: 1722 - * 1723 - * Call context: 1724 - * process 1725 - *---------------------------------------------------------------- 1726 - */ 1727 - int hfa384x_drvr_flashdl_disable(struct hfa384x *hw) 1728 - { 1729 - /* Check that we're already in the download state */ 1730 - if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED) 1731 - return -EINVAL; 1732 - 1733 - pr_debug("flashdl_enable\n"); 1734 - 1735 - /* There isn't much we can do at this point, so I don't */ 1736 - /* bother w/ the return value */ 1737 - hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0); 1738 - hw->dlstate = HFA384x_DLSTATE_DISABLED; 1739 - 1740 - return 0; 1741 - } 1742 - 1743 - /*---------------------------------------------------------------- 1744 - * hfa384x_drvr_flashdl_write 1745 - * 1746 - * Performs a FLASH download of a chunk of data. First checks to see 1747 - * that we're in the FLASH download state, then sets the download 1748 - * mode, uses the aux functions to 1) copy the data to the flash 1749 - * buffer, 2) sets the download 'write flash' mode, 3) readback and 1750 - * compare. Lather rinse, repeat as many times an necessary to get 1751 - * all the given data into flash. 1752 - * When all data has been written using this function (possibly 1753 - * repeatedly), call drvr_flashdl_disable() to end the download state 1754 - * and restart the MAC. 1755 - * 1756 - * Arguments: 1757 - * hw device structure 1758 - * daddr Card address to write to. (host order) 1759 - * buf Ptr to data to write. 1760 - * len Length of data (host order). 1761 - * 1762 - * Returns: 1763 - * 0 success 1764 - * >0 f/w reported error - f/w status code 1765 - * <0 driver reported error 1766 - * 1767 - * Side effects: 1768 - * 1769 - * Call context: 1770 - * process 1771 - *---------------------------------------------------------------- 1772 - */ 1773 - int hfa384x_drvr_flashdl_write(struct hfa384x *hw, u32 daddr, 1774 - void *buf, u32 len) 1775 - { 1776 - int result = 0; 1777 - u32 dlbufaddr; 1778 - int nburns; 1779 - u32 burnlen; 1780 - u32 burndaddr; 1781 - u16 burnlo; 1782 - u16 burnhi; 1783 - int nwrites; 1784 - u8 *writebuf; 1785 - u16 writepage; 1786 - u16 writeoffset; 1787 - u32 writelen; 1788 - int i; 1789 - int j; 1790 - 1791 - pr_debug("daddr=0x%08x len=%d\n", daddr, len); 1792 - 1793 - /* Check that we're in the flash download state */ 1794 - if (hw->dlstate != HFA384x_DLSTATE_FLASHENABLED) 1795 - return -EINVAL; 1796 - 1797 - netdev_info(hw->wlandev->netdev, 1798 - "Download %d bytes to flash @0x%06x\n", len, daddr); 1799 - 1800 - /* Convert to flat address for arithmetic */ 1801 - /* NOTE: dlbuffer RID stores the address in AUX format */ 1802 - dlbufaddr = 1803 - HFA384x_ADDR_AUX_MKFLAT(hw->bufinfo.page, hw->bufinfo.offset); 1804 - pr_debug("dlbuf.page=0x%04x dlbuf.offset=0x%04x dlbufaddr=0x%08x\n", 1805 - hw->bufinfo.page, hw->bufinfo.offset, dlbufaddr); 1806 - /* Calculations to determine how many fills of the dlbuffer to do 1807 - * and how many USB wmemreq's to do for each fill. At this point 1808 - * in time, the dlbuffer size and the wmemreq size are the same. 1809 - * Therefore, nwrites should always be 1. The extra complexity 1810 - * here is a hedge against future changes. 1811 - */ 1812 - 1813 - /* Figure out how many times to do the flash programming */ 1814 - nburns = len / hw->bufinfo.len; 1815 - nburns += (len % hw->bufinfo.len) ? 1 : 0; 1816 - 1817 - /* For each flash program cycle, how many USB wmemreq's are needed? */ 1818 - nwrites = hw->bufinfo.len / HFA384x_USB_RWMEM_MAXLEN; 1819 - nwrites += (hw->bufinfo.len % HFA384x_USB_RWMEM_MAXLEN) ? 1 : 0; 1820 - 1821 - /* For each burn */ 1822 - for (i = 0; i < nburns; i++) { 1823 - /* Get the dest address and len */ 1824 - burnlen = (len - (hw->bufinfo.len * i)) > hw->bufinfo.len ? 1825 - hw->bufinfo.len : (len - (hw->bufinfo.len * i)); 1826 - burndaddr = daddr + (hw->bufinfo.len * i); 1827 - burnlo = HFA384x_ADDR_CMD_MKOFF(burndaddr); 1828 - burnhi = HFA384x_ADDR_CMD_MKPAGE(burndaddr); 1829 - 1830 - netdev_info(hw->wlandev->netdev, "Writing %d bytes to flash @0x%06x\n", 1831 - burnlen, burndaddr); 1832 - 1833 - /* Set the download mode */ 1834 - result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_NV, 1835 - burnlo, burnhi, burnlen); 1836 - if (result) { 1837 - netdev_err(hw->wlandev->netdev, 1838 - "download(NV,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n", 1839 - burnlo, burnhi, burnlen, result); 1840 - goto exit_proc; 1841 - } 1842 - 1843 - /* copy the data to the flash download buffer */ 1844 - for (j = 0; j < nwrites; j++) { 1845 - writebuf = buf + 1846 - (i * hw->bufinfo.len) + 1847 - (j * HFA384x_USB_RWMEM_MAXLEN); 1848 - 1849 - writepage = HFA384x_ADDR_CMD_MKPAGE(dlbufaddr + 1850 - (j * HFA384x_USB_RWMEM_MAXLEN)); 1851 - writeoffset = HFA384x_ADDR_CMD_MKOFF(dlbufaddr + 1852 - (j * HFA384x_USB_RWMEM_MAXLEN)); 1853 - 1854 - writelen = burnlen - (j * HFA384x_USB_RWMEM_MAXLEN); 1855 - writelen = writelen > HFA384x_USB_RWMEM_MAXLEN ? 1856 - HFA384x_USB_RWMEM_MAXLEN : writelen; 1857 - 1858 - result = hfa384x_dowmem(hw, 1859 - writepage, 1860 - writeoffset, 1861 - writebuf, writelen); 1862 - } 1863 - 1864 - /* set the download 'write flash' mode */ 1865 - result = hfa384x_cmd_download(hw, 1866 - HFA384x_PROGMODE_NVWRITE, 1867 - 0, 0, 0); 1868 - if (result) { 1869 - netdev_err(hw->wlandev->netdev, 1870 - "download(NVWRITE,lo=%x,hi=%x,len=%x) cmd failed, result=%d. Aborting d/l\n", 1871 - burnlo, burnhi, burnlen, result); 1872 - goto exit_proc; 1873 - } 1874 - 1875 - /* TODO: We really should do a readback and compare. */ 1876 - } 1877 - 1878 - exit_proc: 1879 - 1880 - /* Leave the firmware in the 'post-prog' mode. flashdl_disable will */ 1881 - /* actually disable programming mode. Remember, that will cause the */ 1882 - /* the firmware to effectively reset itself. */ 1883 - 1884 - return result; 1885 - } 1886 - 1887 - /*---------------------------------------------------------------- 1888 - * hfa384x_drvr_getconfig 1889 - * 1890 - * Performs the sequence necessary to read a config/info item. 1891 - * 1892 - * Arguments: 1893 - * hw device structure 1894 - * rid config/info record id (host order) 1895 - * buf host side record buffer. Upon return it will 1896 - * contain the body portion of the record (minus the 1897 - * RID and len). 1898 - * len buffer length (in bytes, should match record length) 1899 - * 1900 - * Returns: 1901 - * 0 success 1902 - * >0 f/w reported error - f/w status code 1903 - * <0 driver reported error 1904 - * -ENODATA length mismatch between argument and retrieved 1905 - * record. 1906 - * 1907 - * Side effects: 1908 - * 1909 - * Call context: 1910 - * process 1911 - *---------------------------------------------------------------- 1912 - */ 1913 - int hfa384x_drvr_getconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len) 1914 - { 1915 - return hfa384x_dorrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL); 1916 - } 1917 - 1918 - /*---------------------------------------------------------------- 1919 - * hfa384x_drvr_setconfig_async 1920 - * 1921 - * Performs the sequence necessary to write a config/info item. 1922 - * 1923 - * Arguments: 1924 - * hw device structure 1925 - * rid config/info record id (in host order) 1926 - * buf host side record buffer 1927 - * len buffer length (in bytes) 1928 - * usercb completion callback 1929 - * usercb_data completion callback argument 1930 - * 1931 - * Returns: 1932 - * 0 success 1933 - * >0 f/w reported error - f/w status code 1934 - * <0 driver reported error 1935 - * 1936 - * Side effects: 1937 - * 1938 - * Call context: 1939 - * process 1940 - *---------------------------------------------------------------- 1941 - */ 1942 - int 1943 - hfa384x_drvr_setconfig_async(struct hfa384x *hw, 1944 - u16 rid, 1945 - void *buf, 1946 - u16 len, ctlx_usercb_t usercb, void *usercb_data) 1947 - { 1948 - return hfa384x_dowrid(hw, DOASYNC, rid, buf, len, hfa384x_cb_status, 1949 - usercb, usercb_data); 1950 - } 1951 - 1952 - /*---------------------------------------------------------------- 1953 - * hfa384x_drvr_ramdl_disable 1954 - * 1955 - * Ends the ram download state. 1956 - * 1957 - * Arguments: 1958 - * hw device structure 1959 - * 1960 - * Returns: 1961 - * 0 success 1962 - * >0 f/w reported error - f/w status code 1963 - * <0 driver reported error 1964 - * 1965 - * Side effects: 1966 - * 1967 - * Call context: 1968 - * process 1969 - *---------------------------------------------------------------- 1970 - */ 1971 - int hfa384x_drvr_ramdl_disable(struct hfa384x *hw) 1972 - { 1973 - /* Check that we're already in the download state */ 1974 - if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED) 1975 - return -EINVAL; 1976 - 1977 - pr_debug("ramdl_disable()\n"); 1978 - 1979 - /* There isn't much we can do at this point, so I don't */ 1980 - /* bother w/ the return value */ 1981 - hfa384x_cmd_download(hw, HFA384x_PROGMODE_DISABLE, 0, 0, 0); 1982 - hw->dlstate = HFA384x_DLSTATE_DISABLED; 1983 - 1984 - return 0; 1985 - } 1986 - 1987 - /*---------------------------------------------------------------- 1988 - * hfa384x_drvr_ramdl_enable 1989 - * 1990 - * Begins the ram download state. Checks to see that we're not 1991 - * already in a download state and that a port isn't enabled. 1992 - * Sets the download state and calls cmd_download with the 1993 - * ENABLE_VOLATILE subcommand and the exeaddr argument. 1994 - * 1995 - * Arguments: 1996 - * hw device structure 1997 - * exeaddr the card execution address that will be 1998 - * jumped to when ramdl_disable() is called 1999 - * (host order). 2000 - * 2001 - * Returns: 2002 - * 0 success 2003 - * >0 f/w reported error - f/w status code 2004 - * <0 driver reported error 2005 - * 2006 - * Side effects: 2007 - * 2008 - * Call context: 2009 - * process 2010 - *---------------------------------------------------------------- 2011 - */ 2012 - int hfa384x_drvr_ramdl_enable(struct hfa384x *hw, u32 exeaddr) 2013 - { 2014 - int result = 0; 2015 - u16 lowaddr; 2016 - u16 hiaddr; 2017 - int i; 2018 - 2019 - /* Check that a port isn't active */ 2020 - for (i = 0; i < HFA384x_PORTID_MAX; i++) { 2021 - if (hw->port_enabled[i]) { 2022 - netdev_err(hw->wlandev->netdev, 2023 - "Can't download with a macport enabled.\n"); 2024 - return -EINVAL; 2025 - } 2026 - } 2027 - 2028 - /* Check that we're not already in a download state */ 2029 - if (hw->dlstate != HFA384x_DLSTATE_DISABLED) { 2030 - netdev_err(hw->wlandev->netdev, 2031 - "Download state not disabled.\n"); 2032 - return -EINVAL; 2033 - } 2034 - 2035 - pr_debug("ramdl_enable, exeaddr=0x%08x\n", exeaddr); 2036 - 2037 - /* Call the download(1,addr) function */ 2038 - lowaddr = HFA384x_ADDR_CMD_MKOFF(exeaddr); 2039 - hiaddr = HFA384x_ADDR_CMD_MKPAGE(exeaddr); 2040 - 2041 - result = hfa384x_cmd_download(hw, HFA384x_PROGMODE_RAM, 2042 - lowaddr, hiaddr, 0); 2043 - 2044 - if (result == 0) { 2045 - /* Set the download state */ 2046 - hw->dlstate = HFA384x_DLSTATE_RAMENABLED; 2047 - } else { 2048 - pr_debug("cmd_download(0x%04x, 0x%04x) failed, result=%d.\n", 2049 - lowaddr, hiaddr, result); 2050 - } 2051 - 2052 - return result; 2053 - } 2054 - 2055 - /*---------------------------------------------------------------- 2056 - * hfa384x_drvr_ramdl_write 2057 - * 2058 - * Performs a RAM download of a chunk of data. First checks to see 2059 - * that we're in the RAM download state, then uses the [read|write]mem USB 2060 - * commands to 1) copy the data, 2) readback and compare. The download 2061 - * state is unaffected. When all data has been written using 2062 - * this function, call drvr_ramdl_disable() to end the download state 2063 - * and restart the MAC. 2064 - * 2065 - * Arguments: 2066 - * hw device structure 2067 - * daddr Card address to write to. (host order) 2068 - * buf Ptr to data to write. 2069 - * len Length of data (host order). 2070 - * 2071 - * Returns: 2072 - * 0 success 2073 - * >0 f/w reported error - f/w status code 2074 - * <0 driver reported error 2075 - * 2076 - * Side effects: 2077 - * 2078 - * Call context: 2079 - * process 2080 - *---------------------------------------------------------------- 2081 - */ 2082 - int hfa384x_drvr_ramdl_write(struct hfa384x *hw, u32 daddr, void *buf, u32 len) 2083 - { 2084 - int result = 0; 2085 - int nwrites; 2086 - u8 *data = buf; 2087 - int i; 2088 - u32 curraddr; 2089 - u16 currpage; 2090 - u16 curroffset; 2091 - u16 currlen; 2092 - 2093 - /* Check that we're in the ram download state */ 2094 - if (hw->dlstate != HFA384x_DLSTATE_RAMENABLED) 2095 - return -EINVAL; 2096 - 2097 - netdev_info(hw->wlandev->netdev, "Writing %d bytes to ram @0x%06x\n", 2098 - len, daddr); 2099 - 2100 - /* How many dowmem calls? */ 2101 - nwrites = len / HFA384x_USB_RWMEM_MAXLEN; 2102 - nwrites += len % HFA384x_USB_RWMEM_MAXLEN ? 1 : 0; 2103 - 2104 - /* Do blocking wmem's */ 2105 - for (i = 0; i < nwrites; i++) { 2106 - /* make address args */ 2107 - curraddr = daddr + (i * HFA384x_USB_RWMEM_MAXLEN); 2108 - currpage = HFA384x_ADDR_CMD_MKPAGE(curraddr); 2109 - curroffset = HFA384x_ADDR_CMD_MKOFF(curraddr); 2110 - currlen = len - (i * HFA384x_USB_RWMEM_MAXLEN); 2111 - if (currlen > HFA384x_USB_RWMEM_MAXLEN) 2112 - currlen = HFA384x_USB_RWMEM_MAXLEN; 2113 - 2114 - /* Do blocking ctlx */ 2115 - result = hfa384x_dowmem(hw, 2116 - currpage, 2117 - curroffset, 2118 - data + (i * HFA384x_USB_RWMEM_MAXLEN), 2119 - currlen); 2120 - 2121 - if (result) 2122 - break; 2123 - 2124 - /* TODO: We really should have a readback. */ 2125 - } 2126 - 2127 - return result; 2128 - } 2129 - 2130 - /*---------------------------------------------------------------- 2131 - * hfa384x_drvr_readpda 2132 - * 2133 - * Performs the sequence to read the PDA space. Note there is no 2134 - * drvr_writepda() function. Writing a PDA is 2135 - * generally implemented by a calling component via calls to 2136 - * cmd_download and writing to the flash download buffer via the 2137 - * aux regs. 2138 - * 2139 - * Arguments: 2140 - * hw device structure 2141 - * buf buffer to store PDA in 2142 - * len buffer length 2143 - * 2144 - * Returns: 2145 - * 0 success 2146 - * >0 f/w reported error - f/w status code 2147 - * <0 driver reported error 2148 - * -ETIMEDOUT timeout waiting for the cmd regs to become 2149 - * available, or waiting for the control reg 2150 - * to indicate the Aux port is enabled. 2151 - * -ENODATA the buffer does NOT contain a valid PDA. 2152 - * Either the card PDA is bad, or the auxdata 2153 - * reads are giving us garbage. 2154 - * 2155 - * 2156 - * Side effects: 2157 - * 2158 - * Call context: 2159 - * process or non-card interrupt. 2160 - *---------------------------------------------------------------- 2161 - */ 2162 - int hfa384x_drvr_readpda(struct hfa384x *hw, void *buf, unsigned int len) 2163 - { 2164 - int result = 0; 2165 - __le16 *pda = buf; 2166 - int pdaok = 0; 2167 - int morepdrs = 1; 2168 - int currpdr = 0; /* word offset of the current pdr */ 2169 - size_t i; 2170 - u16 pdrlen; /* pdr length in bytes, host order */ 2171 - u16 pdrcode; /* pdr code, host order */ 2172 - u16 currpage; 2173 - u16 curroffset; 2174 - struct pdaloc { 2175 - u32 cardaddr; 2176 - u16 auxctl; 2177 - } pdaloc[] = { 2178 - { 2179 - HFA3842_PDA_BASE, 0}, { 2180 - HFA3841_PDA_BASE, 0}, { 2181 - HFA3841_PDA_BOGUS_BASE, 0} 2182 - }; 2183 - 2184 - /* Read the pda from each known address. */ 2185 - for (i = 0; i < ARRAY_SIZE(pdaloc); i++) { 2186 - /* Make address */ 2187 - currpage = HFA384x_ADDR_CMD_MKPAGE(pdaloc[i].cardaddr); 2188 - curroffset = HFA384x_ADDR_CMD_MKOFF(pdaloc[i].cardaddr); 2189 - 2190 - /* units of bytes */ 2191 - result = hfa384x_dormem(hw, currpage, curroffset, buf, 2192 - len); 2193 - 2194 - if (result) { 2195 - netdev_warn(hw->wlandev->netdev, 2196 - "Read from index %zd failed, continuing\n", 2197 - i); 2198 - continue; 2199 - } 2200 - 2201 - /* Test for garbage */ 2202 - pdaok = 1; /* initially assume good */ 2203 - morepdrs = 1; 2204 - while (pdaok && morepdrs) { 2205 - pdrlen = le16_to_cpu(pda[currpdr]) * 2; 2206 - pdrcode = le16_to_cpu(pda[currpdr + 1]); 2207 - /* Test the record length */ 2208 - if (pdrlen > HFA384x_PDR_LEN_MAX || pdrlen == 0) { 2209 - netdev_err(hw->wlandev->netdev, 2210 - "pdrlen invalid=%d\n", pdrlen); 2211 - pdaok = 0; 2212 - break; 2213 - } 2214 - /* Test the code */ 2215 - if (!hfa384x_isgood_pdrcode(pdrcode)) { 2216 - netdev_err(hw->wlandev->netdev, "pdrcode invalid=%d\n", 2217 - pdrcode); 2218 - pdaok = 0; 2219 - break; 2220 - } 2221 - /* Test for completion */ 2222 - if (pdrcode == HFA384x_PDR_END_OF_PDA) 2223 - morepdrs = 0; 2224 - 2225 - /* Move to the next pdr (if necessary) */ 2226 - if (morepdrs) { 2227 - /* note the access to pda[], need words here */ 2228 - currpdr += le16_to_cpu(pda[currpdr]) + 1; 2229 - } 2230 - } 2231 - if (pdaok) { 2232 - netdev_info(hw->wlandev->netdev, 2233 - "PDA Read from 0x%08x in %s space.\n", 2234 - pdaloc[i].cardaddr, 2235 - pdaloc[i].auxctl == 0 ? "EXTDS" : 2236 - pdaloc[i].auxctl == 1 ? "NV" : 2237 - pdaloc[i].auxctl == 2 ? "PHY" : 2238 - pdaloc[i].auxctl == 3 ? "ICSRAM" : 2239 - "<bogus auxctl>"); 2240 - break; 2241 - } 2242 - } 2243 - result = pdaok ? 0 : -ENODATA; 2244 - 2245 - if (result) 2246 - pr_debug("Failure: pda is not okay\n"); 2247 - 2248 - return result; 2249 - } 2250 - 2251 - /*---------------------------------------------------------------- 2252 - * hfa384x_drvr_setconfig 2253 - * 2254 - * Performs the sequence necessary to write a config/info item. 2255 - * 2256 - * Arguments: 2257 - * hw device structure 2258 - * rid config/info record id (in host order) 2259 - * buf host side record buffer 2260 - * len buffer length (in bytes) 2261 - * 2262 - * Returns: 2263 - * 0 success 2264 - * >0 f/w reported error - f/w status code 2265 - * <0 driver reported error 2266 - * 2267 - * Side effects: 2268 - * 2269 - * Call context: 2270 - * process 2271 - *---------------------------------------------------------------- 2272 - */ 2273 - int hfa384x_drvr_setconfig(struct hfa384x *hw, u16 rid, void *buf, u16 len) 2274 - { 2275 - return hfa384x_dowrid(hw, DOWAIT, rid, buf, len, NULL, NULL, NULL); 2276 - } 2277 - 2278 - /*---------------------------------------------------------------- 2279 - * hfa384x_drvr_start 2280 - * 2281 - * Issues the MAC initialize command, sets up some data structures, 2282 - * and enables the interrupts. After this function completes, the 2283 - * low-level stuff should be ready for any/all commands. 2284 - * 2285 - * Arguments: 2286 - * hw device structure 2287 - * Returns: 2288 - * 0 success 2289 - * >0 f/w reported error - f/w status code 2290 - * <0 driver reported error 2291 - * 2292 - * Side effects: 2293 - * 2294 - * Call context: 2295 - * process 2296 - *---------------------------------------------------------------- 2297 - */ 2298 - int hfa384x_drvr_start(struct hfa384x *hw) 2299 - { 2300 - int result, result1, result2; 2301 - u16 status; 2302 - 2303 - might_sleep(); 2304 - 2305 - /* Clear endpoint stalls - but only do this if the endpoint 2306 - * is showing a stall status. Some prism2 cards seem to behave 2307 - * badly if a clear_halt is called when the endpoint is already 2308 - * ok 2309 - */ 2310 - result = 2311 - usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_in, 2312 - &status); 2313 - if (result < 0) { 2314 - netdev_err(hw->wlandev->netdev, "Cannot get bulk in endpoint status.\n"); 2315 - goto done; 2316 - } 2317 - if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_in)) 2318 - netdev_err(hw->wlandev->netdev, "Failed to reset bulk in endpoint.\n"); 2319 - 2320 - result = 2321 - usb_get_std_status(hw->usb, USB_RECIP_ENDPOINT, hw->endp_out, 2322 - &status); 2323 - if (result < 0) { 2324 - netdev_err(hw->wlandev->netdev, "Cannot get bulk out endpoint status.\n"); 2325 - goto done; 2326 - } 2327 - if ((status == 1) && usb_clear_halt(hw->usb, hw->endp_out)) 2328 - netdev_err(hw->wlandev->netdev, "Failed to reset bulk out endpoint.\n"); 2329 - 2330 - /* Synchronous unlink, in case we're trying to restart the driver */ 2331 - usb_kill_urb(&hw->rx_urb); 2332 - 2333 - /* Post the IN urb */ 2334 - result = submit_rx_urb(hw, GFP_KERNEL); 2335 - if (result != 0) { 2336 - netdev_err(hw->wlandev->netdev, 2337 - "Fatal, failed to submit RX URB, result=%d\n", 2338 - result); 2339 - goto done; 2340 - } 2341 - 2342 - /* Call initialize twice, with a 1 second sleep in between. 2343 - * This is a nasty work-around since many prism2 cards seem to 2344 - * need time to settle after an init from cold. The second 2345 - * call to initialize in theory is not necessary - but we call 2346 - * it anyway as a double insurance policy: 2347 - * 1) If the first init should fail, the second may well succeed 2348 - * and the card can still be used 2349 - * 2) It helps ensures all is well with the card after the first 2350 - * init and settle time. 2351 - */ 2352 - result1 = hfa384x_cmd_initialize(hw); 2353 - msleep(1000); 2354 - result = hfa384x_cmd_initialize(hw); 2355 - result2 = result; 2356 - if (result1 != 0) { 2357 - if (result2 != 0) { 2358 - netdev_err(hw->wlandev->netdev, 2359 - "cmd_initialize() failed on two attempts, results %d and %d\n", 2360 - result1, result2); 2361 - usb_kill_urb(&hw->rx_urb); 2362 - goto done; 2363 - } else { 2364 - pr_debug("First cmd_initialize() failed (result %d),\n", 2365 - result1); 2366 - pr_debug("but second attempt succeeded. All should be ok\n"); 2367 - } 2368 - } else if (result2 != 0) { 2369 - netdev_warn(hw->wlandev->netdev, "First cmd_initialize() succeeded, but second attempt failed (result=%d)\n", 2370 - result2); 2371 - netdev_warn(hw->wlandev->netdev, 2372 - "Most likely the card will be functional\n"); 2373 - goto done; 2374 - } 2375 - 2376 - hw->state = HFA384x_STATE_RUNNING; 2377 - 2378 - done: 2379 - return result; 2380 - } 2381 - 2382 - /*---------------------------------------------------------------- 2383 - * hfa384x_drvr_stop 2384 - * 2385 - * Shuts down the MAC to the point where it is safe to unload the 2386 - * driver. Any subsystem that may be holding a data or function 2387 - * ptr into the driver must be cleared/deinitialized. 2388 - * 2389 - * Arguments: 2390 - * hw device structure 2391 - * Returns: 2392 - * 0 success 2393 - * >0 f/w reported error - f/w status code 2394 - * <0 driver reported error 2395 - * 2396 - * Side effects: 2397 - * 2398 - * Call context: 2399 - * process 2400 - *---------------------------------------------------------------- 2401 - */ 2402 - int hfa384x_drvr_stop(struct hfa384x *hw) 2403 - { 2404 - int i; 2405 - 2406 - might_sleep(); 2407 - 2408 - /* There's no need for spinlocks here. The USB "disconnect" 2409 - * function sets this "removed" flag and then calls us. 2410 - */ 2411 - if (!hw->wlandev->hwremoved) { 2412 - /* Call initialize to leave the MAC in its 'reset' state */ 2413 - hfa384x_cmd_initialize(hw); 2414 - 2415 - /* Cancel the rxurb */ 2416 - usb_kill_urb(&hw->rx_urb); 2417 - } 2418 - 2419 - hw->link_status = HFA384x_LINK_NOTCONNECTED; 2420 - hw->state = HFA384x_STATE_INIT; 2421 - 2422 - del_timer_sync(&hw->commsqual_timer); 2423 - 2424 - /* Clear all the port status */ 2425 - for (i = 0; i < HFA384x_NUMPORTS_MAX; i++) 2426 - hw->port_enabled[i] = 0; 2427 - 2428 - return 0; 2429 - } 2430 - 2431 - /*---------------------------------------------------------------- 2432 - * hfa384x_drvr_txframe 2433 - * 2434 - * Takes a frame from prism2sta and queues it for transmission. 2435 - * 2436 - * Arguments: 2437 - * hw device structure 2438 - * skb packet buffer struct. Contains an 802.11 2439 - * data frame. 2440 - * p80211_hdr points to the 802.11 header for the packet. 2441 - * Returns: 2442 - * 0 Success and more buffs available 2443 - * 1 Success but no more buffs 2444 - * 2 Allocation failure 2445 - * 4 Buffer full or queue busy 2446 - * 2447 - * Side effects: 2448 - * 2449 - * Call context: 2450 - * interrupt 2451 - *---------------------------------------------------------------- 2452 - */ 2453 - int hfa384x_drvr_txframe(struct hfa384x *hw, struct sk_buff *skb, 2454 - struct p80211_hdr *p80211_hdr, 2455 - struct p80211_metawep *p80211_wep) 2456 - { 2457 - int usbpktlen = sizeof(struct hfa384x_tx_frame); 2458 - int result; 2459 - int ret; 2460 - char *ptr; 2461 - 2462 - if (hw->tx_urb.status == -EINPROGRESS) { 2463 - netdev_warn(hw->wlandev->netdev, "TX URB already in use\n"); 2464 - result = 3; 2465 - goto exit; 2466 - } 2467 - 2468 - /* Build Tx frame structure */ 2469 - /* Set up the control field */ 2470 - memset(&hw->txbuff.txfrm.desc, 0, sizeof(hw->txbuff.txfrm.desc)); 2471 - 2472 - /* Setup the usb type field */ 2473 - hw->txbuff.type = cpu_to_le16(HFA384x_USB_TXFRM); 2474 - 2475 - /* Set up the sw_support field to identify this frame */ 2476 - hw->txbuff.txfrm.desc.sw_support = 0x0123; 2477 - 2478 - /* Tx complete and Tx exception disable per dleach. Might be causing 2479 - * buf depletion 2480 - */ 2481 - /* #define DOEXC SLP -- doboth breaks horribly under load, doexc less so. */ 2482 - #if defined(DOBOTH) 2483 - hw->txbuff.txfrm.desc.tx_control = 2484 - HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | 2485 - HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(1); 2486 - #elif defined(DOEXC) 2487 - hw->txbuff.txfrm.desc.tx_control = 2488 - HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | 2489 - HFA384x_TX_TXEX_SET(1) | HFA384x_TX_TXOK_SET(0); 2490 - #else 2491 - hw->txbuff.txfrm.desc.tx_control = 2492 - HFA384x_TX_MACPORT_SET(0) | HFA384x_TX_STRUCTYPE_SET(1) | 2493 - HFA384x_TX_TXEX_SET(0) | HFA384x_TX_TXOK_SET(0); 2494 - #endif 2495 - cpu_to_le16s(&hw->txbuff.txfrm.desc.tx_control); 2496 - 2497 - /* copy the header over to the txdesc */ 2498 - hw->txbuff.txfrm.desc.hdr = *p80211_hdr; 2499 - 2500 - /* if we're using host WEP, increase size by IV+ICV */ 2501 - if (p80211_wep->data) { 2502 - hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len + 8); 2503 - usbpktlen += 8; 2504 - } else { 2505 - hw->txbuff.txfrm.desc.data_len = cpu_to_le16(skb->len); 2506 - } 2507 - 2508 - usbpktlen += skb->len; 2509 - 2510 - /* copy over the WEP IV if we are using host WEP */ 2511 - ptr = hw->txbuff.txfrm.data; 2512 - if (p80211_wep->data) { 2513 - memcpy(ptr, p80211_wep->iv, sizeof(p80211_wep->iv)); 2514 - ptr += sizeof(p80211_wep->iv); 2515 - memcpy(ptr, p80211_wep->data, skb->len); 2516 - } else { 2517 - memcpy(ptr, skb->data, skb->len); 2518 - } 2519 - /* copy over the packet data */ 2520 - ptr += skb->len; 2521 - 2522 - /* copy over the WEP ICV if we are using host WEP */ 2523 - if (p80211_wep->data) 2524 - memcpy(ptr, p80211_wep->icv, sizeof(p80211_wep->icv)); 2525 - 2526 - /* Send the USB packet */ 2527 - usb_fill_bulk_urb(&hw->tx_urb, hw->usb, 2528 - hw->endp_out, 2529 - &hw->txbuff, ROUNDUP64(usbpktlen), 2530 - hfa384x_usbout_callback, hw->wlandev); 2531 - hw->tx_urb.transfer_flags |= USB_QUEUE_BULK; 2532 - 2533 - result = 1; 2534 - ret = submit_tx_urb(hw, &hw->tx_urb, GFP_ATOMIC); 2535 - if (ret != 0) { 2536 - netdev_err(hw->wlandev->netdev, 2537 - "submit_tx_urb() failed, error=%d\n", ret); 2538 - result = 3; 2539 - } 2540 - 2541 - exit: 2542 - return result; 2543 - } 2544 - 2545 - void hfa384x_tx_timeout(struct wlandevice *wlandev) 2546 - { 2547 - struct hfa384x *hw = wlandev->priv; 2548 - unsigned long flags; 2549 - 2550 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 2551 - 2552 - if (!hw->wlandev->hwremoved) { 2553 - int sched; 2554 - 2555 - sched = !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags); 2556 - sched |= !test_and_set_bit(WORK_RX_HALT, &hw->usb_flags); 2557 - if (sched) 2558 - schedule_work(&hw->usb_work); 2559 - } 2560 - 2561 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 2562 - } 2563 - 2564 - /*---------------------------------------------------------------- 2565 - * hfa384x_usbctlx_reaper_task 2566 - * 2567 - * Deferred work callback to delete dead CTLX objects 2568 - * 2569 - * Arguments: 2570 - * work contains ptr to a struct hfa384x 2571 - * 2572 - * Returns: 2573 - * 2574 - * Call context: 2575 - * Task 2576 - *---------------------------------------------------------------- 2577 - */ 2578 - static void hfa384x_usbctlx_reaper_task(struct work_struct *work) 2579 - { 2580 - struct hfa384x *hw = container_of(work, struct hfa384x, reaper_bh); 2581 - struct hfa384x_usbctlx *ctlx, *temp; 2582 - unsigned long flags; 2583 - 2584 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 2585 - 2586 - /* This list is guaranteed to be empty if someone 2587 - * has unplugged the adapter. 2588 - */ 2589 - list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.reapable, list) { 2590 - list_del(&ctlx->list); 2591 - kfree(ctlx); 2592 - } 2593 - 2594 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 2595 - } 2596 - 2597 - /*---------------------------------------------------------------- 2598 - * hfa384x_usbctlx_completion_task 2599 - * 2600 - * Deferred work callback to call completion handlers for returned CTLXs 2601 - * 2602 - * Arguments: 2603 - * work contains ptr to a struct hfa384x 2604 - * 2605 - * Returns: 2606 - * Nothing 2607 - * 2608 - * Call context: 2609 - * Task 2610 - *---------------------------------------------------------------- 2611 - */ 2612 - static void hfa384x_usbctlx_completion_task(struct work_struct *work) 2613 - { 2614 - struct hfa384x *hw = container_of(work, struct hfa384x, completion_bh); 2615 - struct hfa384x_usbctlx *ctlx, *temp; 2616 - unsigned long flags; 2617 - 2618 - int reap = 0; 2619 - 2620 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 2621 - 2622 - /* This list is guaranteed to be empty if someone 2623 - * has unplugged the adapter ... 2624 - */ 2625 - list_for_each_entry_safe(ctlx, temp, &hw->ctlxq.completing, list) { 2626 - /* Call the completion function that this 2627 - * command was assigned, assuming it has one. 2628 - */ 2629 - if (ctlx->cmdcb) { 2630 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 2631 - ctlx->cmdcb(hw, ctlx); 2632 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 2633 - 2634 - /* Make sure we don't try and complete 2635 - * this CTLX more than once! 2636 - */ 2637 - ctlx->cmdcb = NULL; 2638 - 2639 - /* Did someone yank the adapter out 2640 - * while our list was (briefly) unlocked? 2641 - */ 2642 - if (hw->wlandev->hwremoved) { 2643 - reap = 0; 2644 - break; 2645 - } 2646 - } 2647 - 2648 - /* 2649 - * "Reapable" CTLXs are ones which don't have any 2650 - * threads waiting for them to die. Hence they must 2651 - * be delivered to The Reaper! 2652 - */ 2653 - if (ctlx->reapable) { 2654 - /* Move the CTLX off the "completing" list (hopefully) 2655 - * on to the "reapable" list where the reaper task 2656 - * can find it. And "reapable" means that this CTLX 2657 - * isn't sitting on a wait-queue somewhere. 2658 - */ 2659 - list_move_tail(&ctlx->list, &hw->ctlxq.reapable); 2660 - reap = 1; 2661 - } 2662 - 2663 - complete(&ctlx->done); 2664 - } 2665 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 2666 - 2667 - if (reap) 2668 - schedule_work(&hw->reaper_bh); 2669 - } 2670 - 2671 - /*---------------------------------------------------------------- 2672 - * unlocked_usbctlx_cancel_async 2673 - * 2674 - * Mark the CTLX dead asynchronously, and ensure that the 2675 - * next command on the queue is run afterwards. 2676 - * 2677 - * Arguments: 2678 - * hw ptr to the struct hfa384x structure 2679 - * ctlx ptr to a CTLX structure 2680 - * 2681 - * Returns: 2682 - * 0 the CTLX's URB is inactive 2683 - * -EINPROGRESS the URB is currently being unlinked 2684 - * 2685 - * Call context: 2686 - * Either process or interrupt, but presumably interrupt 2687 - *---------------------------------------------------------------- 2688 - */ 2689 - static int unlocked_usbctlx_cancel_async(struct hfa384x *hw, 2690 - struct hfa384x_usbctlx *ctlx) 2691 - { 2692 - int ret; 2693 - 2694 - /* 2695 - * Try to delete the URB containing our request packet. 2696 - * If we succeed, then its completion handler will be 2697 - * called with a status of -ECONNRESET. 2698 - */ 2699 - hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK; 2700 - ret = usb_unlink_urb(&hw->ctlx_urb); 2701 - 2702 - if (ret != -EINPROGRESS) { 2703 - /* 2704 - * The OUT URB had either already completed 2705 - * or was still in the pending queue, so the 2706 - * URB's completion function will not be called. 2707 - * We will have to complete the CTLX ourselves. 2708 - */ 2709 - ctlx->state = CTLX_REQ_FAILED; 2710 - unlocked_usbctlx_complete(hw, ctlx); 2711 - ret = 0; 2712 - } 2713 - 2714 - return ret; 2715 - } 2716 - 2717 - /*---------------------------------------------------------------- 2718 - * unlocked_usbctlx_complete 2719 - * 2720 - * A CTLX has completed. It may have been successful, it may not 2721 - * have been. At this point, the CTLX should be quiescent. The URBs 2722 - * aren't active and the timers should have been stopped. 2723 - * 2724 - * The CTLX is migrated to the "completing" queue, and the completing 2725 - * work is scheduled. 2726 - * 2727 - * Arguments: 2728 - * hw ptr to a struct hfa384x structure 2729 - * ctlx ptr to a ctlx structure 2730 - * 2731 - * Returns: 2732 - * nothing 2733 - * 2734 - * Side effects: 2735 - * 2736 - * Call context: 2737 - * Either, assume interrupt 2738 - *---------------------------------------------------------------- 2739 - */ 2740 - static void unlocked_usbctlx_complete(struct hfa384x *hw, 2741 - struct hfa384x_usbctlx *ctlx) 2742 - { 2743 - /* Timers have been stopped, and ctlx should be in 2744 - * a terminal state. Retire it from the "active" 2745 - * queue. 2746 - */ 2747 - list_move_tail(&ctlx->list, &hw->ctlxq.completing); 2748 - schedule_work(&hw->completion_bh); 2749 - 2750 - switch (ctlx->state) { 2751 - case CTLX_COMPLETE: 2752 - case CTLX_REQ_FAILED: 2753 - /* This are the correct terminating states. */ 2754 - break; 2755 - 2756 - default: 2757 - netdev_err(hw->wlandev->netdev, "CTLX[%d] not in a terminating state(%s)\n", 2758 - le16_to_cpu(ctlx->outbuf.type), 2759 - ctlxstr(ctlx->state)); 2760 - break; 2761 - } /* switch */ 2762 - } 2763 - 2764 - /*---------------------------------------------------------------- 2765 - * hfa384x_usbctlxq_run 2766 - * 2767 - * Checks to see if the head item is running. If not, starts it. 2768 - * 2769 - * Arguments: 2770 - * hw ptr to struct hfa384x 2771 - * 2772 - * Returns: 2773 - * nothing 2774 - * 2775 - * Side effects: 2776 - * 2777 - * Call context: 2778 - * any 2779 - *---------------------------------------------------------------- 2780 - */ 2781 - static void hfa384x_usbctlxq_run(struct hfa384x *hw) 2782 - { 2783 - unsigned long flags; 2784 - 2785 - /* acquire lock */ 2786 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 2787 - 2788 - /* Only one active CTLX at any one time, because there's no 2789 - * other (reliable) way to match the response URB to the 2790 - * correct CTLX. 2791 - * 2792 - * Don't touch any of these CTLXs if the hardware 2793 - * has been removed or the USB subsystem is stalled. 2794 - */ 2795 - if (!list_empty(&hw->ctlxq.active) || 2796 - test_bit(WORK_TX_HALT, &hw->usb_flags) || hw->wlandev->hwremoved) 2797 - goto unlock; 2798 - 2799 - while (!list_empty(&hw->ctlxq.pending)) { 2800 - struct hfa384x_usbctlx *head; 2801 - int result; 2802 - 2803 - /* This is the first pending command */ 2804 - head = list_entry(hw->ctlxq.pending.next, 2805 - struct hfa384x_usbctlx, list); 2806 - 2807 - /* We need to split this off to avoid a race condition */ 2808 - list_move_tail(&head->list, &hw->ctlxq.active); 2809 - 2810 - /* Fill the out packet */ 2811 - usb_fill_bulk_urb(&hw->ctlx_urb, hw->usb, 2812 - hw->endp_out, 2813 - &head->outbuf, ROUNDUP64(head->outbufsize), 2814 - hfa384x_ctlxout_callback, hw); 2815 - hw->ctlx_urb.transfer_flags |= USB_QUEUE_BULK; 2816 - 2817 - /* Now submit the URB and update the CTLX's state */ 2818 - result = usb_submit_urb(&hw->ctlx_urb, GFP_ATOMIC); 2819 - if (result == 0) { 2820 - /* This CTLX is now running on the active queue */ 2821 - head->state = CTLX_REQ_SUBMITTED; 2822 - 2823 - /* Start the OUT wait timer */ 2824 - hw->req_timer_done = 0; 2825 - hw->reqtimer.expires = jiffies + HZ; 2826 - add_timer(&hw->reqtimer); 2827 - 2828 - /* Start the IN wait timer */ 2829 - hw->resp_timer_done = 0; 2830 - hw->resptimer.expires = jiffies + 2 * HZ; 2831 - add_timer(&hw->resptimer); 2832 - 2833 - break; 2834 - } 2835 - 2836 - if (result == -EPIPE) { 2837 - /* The OUT pipe needs resetting, so put 2838 - * this CTLX back in the "pending" queue 2839 - * and schedule a reset ... 2840 - */ 2841 - netdev_warn(hw->wlandev->netdev, 2842 - "%s tx pipe stalled: requesting reset\n", 2843 - hw->wlandev->netdev->name); 2844 - list_move(&head->list, &hw->ctlxq.pending); 2845 - set_bit(WORK_TX_HALT, &hw->usb_flags); 2846 - schedule_work(&hw->usb_work); 2847 - break; 2848 - } 2849 - 2850 - if (result == -ESHUTDOWN) { 2851 - netdev_warn(hw->wlandev->netdev, "%s urb shutdown!\n", 2852 - hw->wlandev->netdev->name); 2853 - break; 2854 - } 2855 - 2856 - netdev_err(hw->wlandev->netdev, "Failed to submit CTLX[%d]: error=%d\n", 2857 - le16_to_cpu(head->outbuf.type), result); 2858 - unlocked_usbctlx_complete(hw, head); 2859 - } /* while */ 2860 - 2861 - unlock: 2862 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 2863 - } 2864 - 2865 - /*---------------------------------------------------------------- 2866 - * hfa384x_usbin_callback 2867 - * 2868 - * Callback for URBs on the BULKIN endpoint. 2869 - * 2870 - * Arguments: 2871 - * urb ptr to the completed urb 2872 - * 2873 - * Returns: 2874 - * nothing 2875 - * 2876 - * Side effects: 2877 - * 2878 - * Call context: 2879 - * interrupt 2880 - *---------------------------------------------------------------- 2881 - */ 2882 - static void hfa384x_usbin_callback(struct urb *urb) 2883 - { 2884 - struct wlandevice *wlandev = urb->context; 2885 - struct hfa384x *hw; 2886 - union hfa384x_usbin *usbin; 2887 - struct sk_buff *skb = NULL; 2888 - int result; 2889 - int urb_status; 2890 - u16 type; 2891 - 2892 - enum USBIN_ACTION { 2893 - HANDLE, 2894 - RESUBMIT, 2895 - ABORT 2896 - } action; 2897 - 2898 - if (!wlandev || !wlandev->netdev || wlandev->hwremoved) 2899 - goto exit; 2900 - 2901 - hw = wlandev->priv; 2902 - if (!hw) 2903 - goto exit; 2904 - 2905 - skb = hw->rx_urb_skb; 2906 - if (!skb || (skb->data != urb->transfer_buffer)) { 2907 - WARN_ON(1); 2908 - return; 2909 - } 2910 - 2911 - hw->rx_urb_skb = NULL; 2912 - 2913 - /* Check for error conditions within the URB */ 2914 - switch (urb->status) { 2915 - case 0: 2916 - action = HANDLE; 2917 - 2918 - /* Check for short packet */ 2919 - if (urb->actual_length == 0) { 2920 - wlandev->netdev->stats.rx_errors++; 2921 - wlandev->netdev->stats.rx_length_errors++; 2922 - action = RESUBMIT; 2923 - } 2924 - break; 2925 - 2926 - case -EPIPE: 2927 - netdev_warn(hw->wlandev->netdev, "%s rx pipe stalled: requesting reset\n", 2928 - wlandev->netdev->name); 2929 - if (!test_and_set_bit(WORK_RX_HALT, &hw->usb_flags)) 2930 - schedule_work(&hw->usb_work); 2931 - wlandev->netdev->stats.rx_errors++; 2932 - action = ABORT; 2933 - break; 2934 - 2935 - case -EILSEQ: 2936 - case -ETIMEDOUT: 2937 - case -EPROTO: 2938 - if (!test_and_set_bit(THROTTLE_RX, &hw->usb_flags) && 2939 - !timer_pending(&hw->throttle)) { 2940 - mod_timer(&hw->throttle, jiffies + THROTTLE_JIFFIES); 2941 - } 2942 - wlandev->netdev->stats.rx_errors++; 2943 - action = ABORT; 2944 - break; 2945 - 2946 - case -EOVERFLOW: 2947 - wlandev->netdev->stats.rx_over_errors++; 2948 - action = RESUBMIT; 2949 - break; 2950 - 2951 - case -ENODEV: 2952 - case -ESHUTDOWN: 2953 - pr_debug("status=%d, device removed.\n", urb->status); 2954 - action = ABORT; 2955 - break; 2956 - 2957 - case -ENOENT: 2958 - case -ECONNRESET: 2959 - pr_debug("status=%d, urb explicitly unlinked.\n", urb->status); 2960 - action = ABORT; 2961 - break; 2962 - 2963 - default: 2964 - pr_debug("urb status=%d, transfer flags=0x%x\n", 2965 - urb->status, urb->transfer_flags); 2966 - wlandev->netdev->stats.rx_errors++; 2967 - action = RESUBMIT; 2968 - break; 2969 - } 2970 - 2971 - /* Save values from the RX URB before reposting overwrites it. */ 2972 - urb_status = urb->status; 2973 - usbin = (union hfa384x_usbin *)urb->transfer_buffer; 2974 - 2975 - if (action != ABORT) { 2976 - /* Repost the RX URB */ 2977 - result = submit_rx_urb(hw, GFP_ATOMIC); 2978 - 2979 - if (result != 0) { 2980 - netdev_err(hw->wlandev->netdev, 2981 - "Fatal, failed to resubmit rx_urb. error=%d\n", 2982 - result); 2983 - } 2984 - } 2985 - 2986 - /* Handle any USB-IN packet */ 2987 - /* Note: the check of the sw_support field, the type field doesn't 2988 - * have bit 12 set like the docs suggest. 2989 - */ 2990 - type = le16_to_cpu(usbin->type); 2991 - if (HFA384x_USB_ISRXFRM(type)) { 2992 - if (action == HANDLE) { 2993 - if (usbin->txfrm.desc.sw_support == 0x0123) { 2994 - hfa384x_usbin_txcompl(wlandev, usbin); 2995 - } else { 2996 - skb_put(skb, sizeof(*usbin)); 2997 - hfa384x_usbin_rx(wlandev, skb); 2998 - skb = NULL; 2999 - } 3000 - } 3001 - goto exit; 3002 - } 3003 - if (HFA384x_USB_ISTXFRM(type)) { 3004 - if (action == HANDLE) 3005 - hfa384x_usbin_txcompl(wlandev, usbin); 3006 - goto exit; 3007 - } 3008 - switch (type) { 3009 - case HFA384x_USB_INFOFRM: 3010 - if (action == ABORT) 3011 - goto exit; 3012 - if (action == HANDLE) 3013 - hfa384x_usbin_info(wlandev, usbin); 3014 - break; 3015 - 3016 - case HFA384x_USB_CMDRESP: 3017 - case HFA384x_USB_WRIDRESP: 3018 - case HFA384x_USB_RRIDRESP: 3019 - case HFA384x_USB_WMEMRESP: 3020 - case HFA384x_USB_RMEMRESP: 3021 - /* ALWAYS, ALWAYS, ALWAYS handle this CTLX!!!! */ 3022 - hfa384x_usbin_ctlx(hw, usbin, urb_status); 3023 - break; 3024 - 3025 - case HFA384x_USB_BUFAVAIL: 3026 - pr_debug("Received BUFAVAIL packet, frmlen=%d\n", 3027 - usbin->bufavail.frmlen); 3028 - break; 3029 - 3030 - case HFA384x_USB_ERROR: 3031 - pr_debug("Received USB_ERROR packet, errortype=%d\n", 3032 - usbin->usberror.errortype); 3033 - break; 3034 - 3035 - default: 3036 - pr_debug("Unrecognized USBIN packet, type=%x, status=%d\n", 3037 - usbin->type, urb_status); 3038 - break; 3039 - } /* switch */ 3040 - 3041 - exit: 3042 - 3043 - if (skb) 3044 - dev_kfree_skb(skb); 3045 - } 3046 - 3047 - /*---------------------------------------------------------------- 3048 - * hfa384x_usbin_ctlx 3049 - * 3050 - * We've received a URB containing a Prism2 "response" message. 3051 - * This message needs to be matched up with a CTLX on the active 3052 - * queue and our state updated accordingly. 3053 - * 3054 - * Arguments: 3055 - * hw ptr to struct hfa384x 3056 - * usbin ptr to USB IN packet 3057 - * urb_status status of this Bulk-In URB 3058 - * 3059 - * Returns: 3060 - * nothing 3061 - * 3062 - * Side effects: 3063 - * 3064 - * Call context: 3065 - * interrupt 3066 - *---------------------------------------------------------------- 3067 - */ 3068 - static void hfa384x_usbin_ctlx(struct hfa384x *hw, union hfa384x_usbin *usbin, 3069 - int urb_status) 3070 - { 3071 - struct hfa384x_usbctlx *ctlx; 3072 - int run_queue = 0; 3073 - unsigned long flags; 3074 - 3075 - retry: 3076 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3077 - 3078 - /* There can be only one CTLX on the active queue 3079 - * at any one time, and this is the CTLX that the 3080 - * timers are waiting for. 3081 - */ 3082 - if (list_empty(&hw->ctlxq.active)) 3083 - goto unlock; 3084 - 3085 - /* Remove the "response timeout". It's possible that 3086 - * we are already too late, and that the timeout is 3087 - * already running. And that's just too bad for us, 3088 - * because we could lose our CTLX from the active 3089 - * queue here ... 3090 - */ 3091 - if (del_timer(&hw->resptimer) == 0) { 3092 - if (hw->resp_timer_done == 0) { 3093 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3094 - goto retry; 3095 - } 3096 - } else { 3097 - hw->resp_timer_done = 1; 3098 - } 3099 - 3100 - ctlx = get_active_ctlx(hw); 3101 - 3102 - if (urb_status != 0) { 3103 - /* 3104 - * Bad CTLX, so get rid of it. But we only 3105 - * remove it from the active queue if we're no 3106 - * longer expecting the OUT URB to complete. 3107 - */ 3108 - if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) 3109 - run_queue = 1; 3110 - } else { 3111 - const __le16 intype = (usbin->type & ~cpu_to_le16(0x8000)); 3112 - 3113 - /* 3114 - * Check that our message is what we're expecting ... 3115 - */ 3116 - if (ctlx->outbuf.type != intype) { 3117 - netdev_warn(hw->wlandev->netdev, 3118 - "Expected IN[%d], received IN[%d] - ignored.\n", 3119 - le16_to_cpu(ctlx->outbuf.type), 3120 - le16_to_cpu(intype)); 3121 - goto unlock; 3122 - } 3123 - 3124 - /* This URB has succeeded, so grab the data ... */ 3125 - memcpy(&ctlx->inbuf, usbin, sizeof(ctlx->inbuf)); 3126 - 3127 - switch (ctlx->state) { 3128 - case CTLX_REQ_SUBMITTED: 3129 - /* 3130 - * We have received our response URB before 3131 - * our request has been acknowledged. Odd, 3132 - * but our OUT URB is still alive... 3133 - */ 3134 - pr_debug("Causality violation: please reboot Universe\n"); 3135 - ctlx->state = CTLX_RESP_COMPLETE; 3136 - break; 3137 - 3138 - case CTLX_REQ_COMPLETE: 3139 - /* 3140 - * This is the usual path: our request 3141 - * has already been acknowledged, and 3142 - * now we have received the reply too. 3143 - */ 3144 - ctlx->state = CTLX_COMPLETE; 3145 - unlocked_usbctlx_complete(hw, ctlx); 3146 - run_queue = 1; 3147 - break; 3148 - 3149 - default: 3150 - /* 3151 - * Throw this CTLX away ... 3152 - */ 3153 - netdev_err(hw->wlandev->netdev, 3154 - "Matched IN URB, CTLX[%d] in invalid state(%s). Discarded.\n", 3155 - le16_to_cpu(ctlx->outbuf.type), 3156 - ctlxstr(ctlx->state)); 3157 - if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) 3158 - run_queue = 1; 3159 - break; 3160 - } /* switch */ 3161 - } 3162 - 3163 - unlock: 3164 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3165 - 3166 - if (run_queue) 3167 - hfa384x_usbctlxq_run(hw); 3168 - } 3169 - 3170 - /*---------------------------------------------------------------- 3171 - * hfa384x_usbin_txcompl 3172 - * 3173 - * At this point we have the results of a previous transmit. 3174 - * 3175 - * Arguments: 3176 - * wlandev wlan device 3177 - * usbin ptr to the usb transfer buffer 3178 - * 3179 - * Returns: 3180 - * nothing 3181 - * 3182 - * Side effects: 3183 - * 3184 - * Call context: 3185 - * interrupt 3186 - *---------------------------------------------------------------- 3187 - */ 3188 - static void hfa384x_usbin_txcompl(struct wlandevice *wlandev, 3189 - union hfa384x_usbin *usbin) 3190 - { 3191 - u16 status; 3192 - 3193 - status = le16_to_cpu(usbin->type); /* yeah I know it says type... */ 3194 - 3195 - /* Was there an error? */ 3196 - if (HFA384x_TXSTATUS_ISERROR(status)) 3197 - netdev_dbg(wlandev->netdev, "TxExc status=0x%x.\n", status); 3198 - else 3199 - prism2sta_ev_tx(wlandev, status); 3200 - } 3201 - 3202 - /*---------------------------------------------------------------- 3203 - * hfa384x_usbin_rx 3204 - * 3205 - * At this point we have a successful received a rx frame packet. 3206 - * 3207 - * Arguments: 3208 - * wlandev wlan device 3209 - * usbin ptr to the usb transfer buffer 3210 - * 3211 - * Returns: 3212 - * nothing 3213 - * 3214 - * Side effects: 3215 - * 3216 - * Call context: 3217 - * interrupt 3218 - *---------------------------------------------------------------- 3219 - */ 3220 - static void hfa384x_usbin_rx(struct wlandevice *wlandev, struct sk_buff *skb) 3221 - { 3222 - union hfa384x_usbin *usbin = (union hfa384x_usbin *)skb->data; 3223 - struct hfa384x *hw = wlandev->priv; 3224 - int hdrlen; 3225 - struct p80211_rxmeta *rxmeta; 3226 - u16 data_len; 3227 - u16 fc; 3228 - u16 status; 3229 - 3230 - /* Byte order convert once up front. */ 3231 - le16_to_cpus(&usbin->rxfrm.desc.status); 3232 - le32_to_cpus(&usbin->rxfrm.desc.time); 3233 - 3234 - /* Now handle frame based on port# */ 3235 - status = HFA384x_RXSTATUS_MACPORT_GET(usbin->rxfrm.desc.status); 3236 - 3237 - switch (status) { 3238 - case 0: 3239 - fc = le16_to_cpu(usbin->rxfrm.desc.hdr.frame_control); 3240 - 3241 - /* If exclude and we receive an unencrypted, drop it */ 3242 - if ((wlandev->hostwep & HOSTWEP_EXCLUDEUNENCRYPTED) && 3243 - !WLAN_GET_FC_ISWEP(fc)) { 3244 - break; 3245 - } 3246 - 3247 - data_len = le16_to_cpu(usbin->rxfrm.desc.data_len); 3248 - 3249 - /* How much header data do we have? */ 3250 - hdrlen = p80211_headerlen(fc); 3251 - 3252 - /* Pull off the descriptor */ 3253 - skb_pull(skb, sizeof(struct hfa384x_rx_frame)); 3254 - 3255 - /* Now shunt the header block up against the data block 3256 - * with an "overlapping" copy 3257 - */ 3258 - memmove(skb_push(skb, hdrlen), 3259 - &usbin->rxfrm.desc.hdr, hdrlen); 3260 - 3261 - skb->dev = wlandev->netdev; 3262 - 3263 - /* And set the frame length properly */ 3264 - skb_trim(skb, data_len + hdrlen); 3265 - 3266 - /* The prism2 series does not return the CRC */ 3267 - memset(skb_put(skb, WLAN_CRC_LEN), 0xff, WLAN_CRC_LEN); 3268 - 3269 - skb_reset_mac_header(skb); 3270 - 3271 - /* Attach the rxmeta, set some stuff */ 3272 - p80211skb_rxmeta_attach(wlandev, skb); 3273 - rxmeta = p80211skb_rxmeta(skb); 3274 - rxmeta->mactime = usbin->rxfrm.desc.time; 3275 - rxmeta->rxrate = usbin->rxfrm.desc.rate; 3276 - rxmeta->signal = usbin->rxfrm.desc.signal - hw->dbmadjust; 3277 - rxmeta->noise = usbin->rxfrm.desc.silence - hw->dbmadjust; 3278 - 3279 - p80211netdev_rx(wlandev, skb); 3280 - 3281 - break; 3282 - 3283 - case 7: 3284 - if (!HFA384x_RXSTATUS_ISFCSERR(usbin->rxfrm.desc.status)) { 3285 - /* Copy to wlansnif skb */ 3286 - hfa384x_int_rxmonitor(wlandev, &usbin->rxfrm); 3287 - dev_kfree_skb(skb); 3288 - } else { 3289 - pr_debug("Received monitor frame: FCSerr set\n"); 3290 - } 3291 - break; 3292 - 3293 - default: 3294 - netdev_warn(hw->wlandev->netdev, 3295 - "Received frame on unsupported port=%d\n", 3296 - status); 3297 - break; 3298 - } 3299 - } 3300 - 3301 - /*---------------------------------------------------------------- 3302 - * hfa384x_int_rxmonitor 3303 - * 3304 - * Helper function for int_rx. Handles monitor frames. 3305 - * Note that this function allocates space for the FCS and sets it 3306 - * to 0xffffffff. The hfa384x doesn't give us the FCS value but the 3307 - * higher layers expect it. 0xffffffff is used as a flag to indicate 3308 - * the FCS is bogus. 3309 - * 3310 - * Arguments: 3311 - * wlandev wlan device structure 3312 - * rxfrm rx descriptor read from card in int_rx 3313 - * 3314 - * Returns: 3315 - * nothing 3316 - * 3317 - * Side effects: 3318 - * Allocates an skb and passes it up via the PF_PACKET interface. 3319 - * Call context: 3320 - * interrupt 3321 - *---------------------------------------------------------------- 3322 - */ 3323 - static void hfa384x_int_rxmonitor(struct wlandevice *wlandev, 3324 - struct hfa384x_usb_rxfrm *rxfrm) 3325 - { 3326 - struct hfa384x_rx_frame *rxdesc = &rxfrm->desc; 3327 - unsigned int hdrlen = 0; 3328 - unsigned int datalen = 0; 3329 - unsigned int skblen = 0; 3330 - u8 *datap; 3331 - u16 fc; 3332 - struct sk_buff *skb; 3333 - struct hfa384x *hw = wlandev->priv; 3334 - 3335 - /* Remember the status, time, and data_len fields are in host order */ 3336 - /* Figure out how big the frame is */ 3337 - fc = le16_to_cpu(rxdesc->hdr.frame_control); 3338 - hdrlen = p80211_headerlen(fc); 3339 - datalen = le16_to_cpu(rxdesc->data_len); 3340 - 3341 - /* Allocate an ind message+framesize skb */ 3342 - skblen = sizeof(struct p80211_caphdr) + hdrlen + datalen + WLAN_CRC_LEN; 3343 - 3344 - /* sanity check the length */ 3345 - if (skblen > 3346 - (sizeof(struct p80211_caphdr) + 3347 - WLAN_HDR_A4_LEN + WLAN_DATA_MAXLEN + WLAN_CRC_LEN)) { 3348 - pr_debug("overlen frm: len=%zd\n", 3349 - skblen - sizeof(struct p80211_caphdr)); 3350 - 3351 - return; 3352 - } 3353 - 3354 - skb = dev_alloc_skb(skblen); 3355 - if (!skb) 3356 - return; 3357 - 3358 - /* only prepend the prism header if in the right mode */ 3359 - if ((wlandev->netdev->type == ARPHRD_IEEE80211_PRISM) && 3360 - (hw->sniffhdr != 0)) { 3361 - struct p80211_caphdr *caphdr; 3362 - /* The NEW header format! */ 3363 - datap = skb_put(skb, sizeof(struct p80211_caphdr)); 3364 - caphdr = (struct p80211_caphdr *)datap; 3365 - 3366 - caphdr->version = htonl(P80211CAPTURE_VERSION); 3367 - caphdr->length = htonl(sizeof(struct p80211_caphdr)); 3368 - caphdr->mactime = __cpu_to_be64(rxdesc->time * 1000); 3369 - caphdr->hosttime = __cpu_to_be64(jiffies); 3370 - caphdr->phytype = htonl(4); /* dss_dot11_b */ 3371 - caphdr->channel = htonl(hw->sniff_channel); 3372 - caphdr->datarate = htonl(rxdesc->rate); 3373 - caphdr->antenna = htonl(0); /* unknown */ 3374 - caphdr->priority = htonl(0); /* unknown */ 3375 - caphdr->ssi_type = htonl(3); /* rssi_raw */ 3376 - caphdr->ssi_signal = htonl(rxdesc->signal); 3377 - caphdr->ssi_noise = htonl(rxdesc->silence); 3378 - caphdr->preamble = htonl(0); /* unknown */ 3379 - caphdr->encoding = htonl(1); /* cck */ 3380 - } 3381 - 3382 - /* Copy the 802.11 header to the skb 3383 - * (ctl frames may be less than a full header) 3384 - */ 3385 - skb_put_data(skb, &rxdesc->hdr.frame_control, hdrlen); 3386 - 3387 - /* If any, copy the data from the card to the skb */ 3388 - if (datalen > 0) { 3389 - datap = skb_put_data(skb, rxfrm->data, datalen); 3390 - 3391 - /* check for unencrypted stuff if WEP bit set. */ 3392 - if (*(datap - hdrlen + 1) & 0x40) /* wep set */ 3393 - if ((*(datap) == 0xaa) && (*(datap + 1) == 0xaa)) 3394 - /* clear wep; it's the 802.2 header! */ 3395 - *(datap - hdrlen + 1) &= 0xbf; 3396 - } 3397 - 3398 - if (hw->sniff_fcs) { 3399 - /* Set the FCS */ 3400 - datap = skb_put(skb, WLAN_CRC_LEN); 3401 - memset(datap, 0xff, WLAN_CRC_LEN); 3402 - } 3403 - 3404 - /* pass it back up */ 3405 - p80211netdev_rx(wlandev, skb); 3406 - } 3407 - 3408 - /*---------------------------------------------------------------- 3409 - * hfa384x_usbin_info 3410 - * 3411 - * At this point we have a successful received a Prism2 info frame. 3412 - * 3413 - * Arguments: 3414 - * wlandev wlan device 3415 - * usbin ptr to the usb transfer buffer 3416 - * 3417 - * Returns: 3418 - * nothing 3419 - * 3420 - * Side effects: 3421 - * 3422 - * Call context: 3423 - * interrupt 3424 - *---------------------------------------------------------------- 3425 - */ 3426 - static void hfa384x_usbin_info(struct wlandevice *wlandev, 3427 - union hfa384x_usbin *usbin) 3428 - { 3429 - le16_to_cpus(&usbin->infofrm.info.framelen); 3430 - prism2sta_ev_info(wlandev, &usbin->infofrm.info); 3431 - } 3432 - 3433 - /*---------------------------------------------------------------- 3434 - * hfa384x_usbout_callback 3435 - * 3436 - * Callback for URBs on the BULKOUT endpoint. 3437 - * 3438 - * Arguments: 3439 - * urb ptr to the completed urb 3440 - * 3441 - * Returns: 3442 - * nothing 3443 - * 3444 - * Side effects: 3445 - * 3446 - * Call context: 3447 - * interrupt 3448 - *---------------------------------------------------------------- 3449 - */ 3450 - static void hfa384x_usbout_callback(struct urb *urb) 3451 - { 3452 - struct wlandevice *wlandev = urb->context; 3453 - 3454 - #ifdef DEBUG_USB 3455 - dbprint_urb(urb); 3456 - #endif 3457 - 3458 - if (wlandev && wlandev->netdev) { 3459 - switch (urb->status) { 3460 - case 0: 3461 - prism2sta_ev_alloc(wlandev); 3462 - break; 3463 - 3464 - case -EPIPE: { 3465 - struct hfa384x *hw = wlandev->priv; 3466 - 3467 - netdev_warn(hw->wlandev->netdev, 3468 - "%s tx pipe stalled: requesting reset\n", 3469 - wlandev->netdev->name); 3470 - if (!test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) 3471 - schedule_work(&hw->usb_work); 3472 - wlandev->netdev->stats.tx_errors++; 3473 - break; 3474 - } 3475 - 3476 - case -EPROTO: 3477 - case -ETIMEDOUT: 3478 - case -EILSEQ: { 3479 - struct hfa384x *hw = wlandev->priv; 3480 - 3481 - if (!test_and_set_bit(THROTTLE_TX, &hw->usb_flags) && 3482 - !timer_pending(&hw->throttle)) { 3483 - mod_timer(&hw->throttle, 3484 - jiffies + THROTTLE_JIFFIES); 3485 - } 3486 - wlandev->netdev->stats.tx_errors++; 3487 - netif_stop_queue(wlandev->netdev); 3488 - break; 3489 - } 3490 - 3491 - case -ENOENT: 3492 - case -ESHUTDOWN: 3493 - /* Ignorable errors */ 3494 - break; 3495 - 3496 - default: 3497 - netdev_info(wlandev->netdev, "unknown urb->status=%d\n", 3498 - urb->status); 3499 - wlandev->netdev->stats.tx_errors++; 3500 - break; 3501 - } /* switch */ 3502 - } 3503 - } 3504 - 3505 - /*---------------------------------------------------------------- 3506 - * hfa384x_ctlxout_callback 3507 - * 3508 - * Callback for control data on the BULKOUT endpoint. 3509 - * 3510 - * Arguments: 3511 - * urb ptr to the completed urb 3512 - * 3513 - * Returns: 3514 - * nothing 3515 - * 3516 - * Side effects: 3517 - * 3518 - * Call context: 3519 - * interrupt 3520 - *---------------------------------------------------------------- 3521 - */ 3522 - static void hfa384x_ctlxout_callback(struct urb *urb) 3523 - { 3524 - struct hfa384x *hw = urb->context; 3525 - int delete_resptimer = 0; 3526 - int timer_ok = 1; 3527 - int run_queue = 0; 3528 - struct hfa384x_usbctlx *ctlx; 3529 - unsigned long flags; 3530 - 3531 - pr_debug("urb->status=%d\n", urb->status); 3532 - #ifdef DEBUG_USB 3533 - dbprint_urb(urb); 3534 - #endif 3535 - if ((urb->status == -ESHUTDOWN) || 3536 - (urb->status == -ENODEV) || !hw) 3537 - return; 3538 - 3539 - retry: 3540 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3541 - 3542 - /* 3543 - * Only one CTLX at a time on the "active" list, and 3544 - * none at all if we are unplugged. However, we can 3545 - * rely on the disconnect function to clean everything 3546 - * up if someone unplugged the adapter. 3547 - */ 3548 - if (list_empty(&hw->ctlxq.active)) { 3549 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3550 - return; 3551 - } 3552 - 3553 - /* 3554 - * Having something on the "active" queue means 3555 - * that we have timers to worry about ... 3556 - */ 3557 - if (del_timer(&hw->reqtimer) == 0) { 3558 - if (hw->req_timer_done == 0) { 3559 - /* 3560 - * This timer was actually running while we 3561 - * were trying to delete it. Let it terminate 3562 - * gracefully instead. 3563 - */ 3564 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3565 - goto retry; 3566 - } 3567 - } else { 3568 - hw->req_timer_done = 1; 3569 - } 3570 - 3571 - ctlx = get_active_ctlx(hw); 3572 - 3573 - if (urb->status == 0) { 3574 - /* Request portion of a CTLX is successful */ 3575 - switch (ctlx->state) { 3576 - case CTLX_REQ_SUBMITTED: 3577 - /* This OUT-ACK received before IN */ 3578 - ctlx->state = CTLX_REQ_COMPLETE; 3579 - break; 3580 - 3581 - case CTLX_RESP_COMPLETE: 3582 - /* IN already received before this OUT-ACK, 3583 - * so this command must now be complete. 3584 - */ 3585 - ctlx->state = CTLX_COMPLETE; 3586 - unlocked_usbctlx_complete(hw, ctlx); 3587 - run_queue = 1; 3588 - break; 3589 - 3590 - default: 3591 - /* This is NOT a valid CTLX "success" state! */ 3592 - netdev_err(hw->wlandev->netdev, 3593 - "Illegal CTLX[%d] success state(%s, %d) in OUT URB\n", 3594 - le16_to_cpu(ctlx->outbuf.type), 3595 - ctlxstr(ctlx->state), urb->status); 3596 - break; 3597 - } /* switch */ 3598 - } else { 3599 - /* If the pipe has stalled then we need to reset it */ 3600 - if ((urb->status == -EPIPE) && 3601 - !test_and_set_bit(WORK_TX_HALT, &hw->usb_flags)) { 3602 - netdev_warn(hw->wlandev->netdev, 3603 - "%s tx pipe stalled: requesting reset\n", 3604 - hw->wlandev->netdev->name); 3605 - schedule_work(&hw->usb_work); 3606 - } 3607 - 3608 - /* If someone cancels the OUT URB then its status 3609 - * should be either -ECONNRESET or -ENOENT. 3610 - */ 3611 - ctlx->state = CTLX_REQ_FAILED; 3612 - unlocked_usbctlx_complete(hw, ctlx); 3613 - delete_resptimer = 1; 3614 - run_queue = 1; 3615 - } 3616 - 3617 - delresp: 3618 - if (delete_resptimer) { 3619 - timer_ok = del_timer(&hw->resptimer); 3620 - if (timer_ok != 0) 3621 - hw->resp_timer_done = 1; 3622 - } 3623 - 3624 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3625 - 3626 - if (!timer_ok && (hw->resp_timer_done == 0)) { 3627 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3628 - goto delresp; 3629 - } 3630 - 3631 - if (run_queue) 3632 - hfa384x_usbctlxq_run(hw); 3633 - } 3634 - 3635 - /*---------------------------------------------------------------- 3636 - * hfa384x_usbctlx_reqtimerfn 3637 - * 3638 - * Timer response function for CTLX request timeouts. If this 3639 - * function is called, it means that the callback for the OUT 3640 - * URB containing a Prism2.x XXX_Request was never called. 3641 - * 3642 - * Arguments: 3643 - * data a ptr to the struct hfa384x 3644 - * 3645 - * Returns: 3646 - * nothing 3647 - * 3648 - * Side effects: 3649 - * 3650 - * Call context: 3651 - * interrupt 3652 - *---------------------------------------------------------------- 3653 - */ 3654 - static void hfa384x_usbctlx_reqtimerfn(struct timer_list *t) 3655 - { 3656 - struct hfa384x *hw = from_timer(hw, t, reqtimer); 3657 - unsigned long flags; 3658 - 3659 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3660 - 3661 - hw->req_timer_done = 1; 3662 - 3663 - /* Removing the hardware automatically empties 3664 - * the active list ... 3665 - */ 3666 - if (!list_empty(&hw->ctlxq.active)) { 3667 - /* 3668 - * We must ensure that our URB is removed from 3669 - * the system, if it hasn't already expired. 3670 - */ 3671 - hw->ctlx_urb.transfer_flags |= URB_ASYNC_UNLINK; 3672 - if (usb_unlink_urb(&hw->ctlx_urb) == -EINPROGRESS) { 3673 - struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw); 3674 - 3675 - ctlx->state = CTLX_REQ_FAILED; 3676 - 3677 - /* This URB was active, but has now been 3678 - * cancelled. It will now have a status of 3679 - * -ECONNRESET in the callback function. 3680 - * 3681 - * We are cancelling this CTLX, so we're 3682 - * not going to need to wait for a response. 3683 - * The URB's callback function will check 3684 - * that this timer is truly dead. 3685 - */ 3686 - if (del_timer(&hw->resptimer) != 0) 3687 - hw->resp_timer_done = 1; 3688 - } 3689 - } 3690 - 3691 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3692 - } 3693 - 3694 - /*---------------------------------------------------------------- 3695 - * hfa384x_usbctlx_resptimerfn 3696 - * 3697 - * Timer response function for CTLX response timeouts. If this 3698 - * function is called, it means that the callback for the IN 3699 - * URB containing a Prism2.x XXX_Response was never called. 3700 - * 3701 - * Arguments: 3702 - * data a ptr to the struct hfa384x 3703 - * 3704 - * Returns: 3705 - * nothing 3706 - * 3707 - * Side effects: 3708 - * 3709 - * Call context: 3710 - * interrupt 3711 - *---------------------------------------------------------------- 3712 - */ 3713 - static void hfa384x_usbctlx_resptimerfn(struct timer_list *t) 3714 - { 3715 - struct hfa384x *hw = from_timer(hw, t, resptimer); 3716 - unsigned long flags; 3717 - 3718 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3719 - 3720 - hw->resp_timer_done = 1; 3721 - 3722 - /* The active list will be empty if the 3723 - * adapter has been unplugged ... 3724 - */ 3725 - if (!list_empty(&hw->ctlxq.active)) { 3726 - struct hfa384x_usbctlx *ctlx = get_active_ctlx(hw); 3727 - 3728 - if (unlocked_usbctlx_cancel_async(hw, ctlx) == 0) { 3729 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3730 - hfa384x_usbctlxq_run(hw); 3731 - return; 3732 - } 3733 - } 3734 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3735 - } 3736 - 3737 - /*---------------------------------------------------------------- 3738 - * hfa384x_usb_throttlefn 3739 - * 3740 - * 3741 - * Arguments: 3742 - * data ptr to hw 3743 - * 3744 - * Returns: 3745 - * Nothing 3746 - * 3747 - * Side effects: 3748 - * 3749 - * Call context: 3750 - * Interrupt 3751 - *---------------------------------------------------------------- 3752 - */ 3753 - static void hfa384x_usb_throttlefn(struct timer_list *t) 3754 - { 3755 - struct hfa384x *hw = from_timer(hw, t, throttle); 3756 - unsigned long flags; 3757 - 3758 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3759 - 3760 - pr_debug("flags=0x%lx\n", hw->usb_flags); 3761 - if (!hw->wlandev->hwremoved) { 3762 - bool rx_throttle = test_and_clear_bit(THROTTLE_RX, &hw->usb_flags) && 3763 - !test_and_set_bit(WORK_RX_RESUME, &hw->usb_flags); 3764 - bool tx_throttle = test_and_clear_bit(THROTTLE_TX, &hw->usb_flags) && 3765 - !test_and_set_bit(WORK_TX_RESUME, &hw->usb_flags); 3766 - /* 3767 - * We need to check BOTH the RX and the TX throttle controls, 3768 - * so we use the bitwise OR instead of the logical OR. 3769 - */ 3770 - if (rx_throttle | tx_throttle) 3771 - schedule_work(&hw->usb_work); 3772 - } 3773 - 3774 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3775 - } 3776 - 3777 - /*---------------------------------------------------------------- 3778 - * hfa384x_usbctlx_submit 3779 - * 3780 - * Called from the doxxx functions to submit a CTLX to the queue 3781 - * 3782 - * Arguments: 3783 - * hw ptr to the hw struct 3784 - * ctlx ctlx structure to enqueue 3785 - * 3786 - * Returns: 3787 - * -ENODEV if the adapter is unplugged 3788 - * 0 3789 - * 3790 - * Side effects: 3791 - * 3792 - * Call context: 3793 - * process or interrupt 3794 - *---------------------------------------------------------------- 3795 - */ 3796 - static int hfa384x_usbctlx_submit(struct hfa384x *hw, 3797 - struct hfa384x_usbctlx *ctlx) 3798 - { 3799 - unsigned long flags; 3800 - 3801 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 3802 - 3803 - if (hw->wlandev->hwremoved) { 3804 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3805 - return -ENODEV; 3806 - } 3807 - 3808 - ctlx->state = CTLX_PENDING; 3809 - list_add_tail(&ctlx->list, &hw->ctlxq.pending); 3810 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 3811 - hfa384x_usbctlxq_run(hw); 3812 - 3813 - return 0; 3814 - } 3815 - 3816 - /*---------------------------------------------------------------- 3817 - * hfa384x_isgood_pdrcore 3818 - * 3819 - * Quick check of PDR codes. 3820 - * 3821 - * Arguments: 3822 - * pdrcode PDR code number (host order) 3823 - * 3824 - * Returns: 3825 - * zero not good. 3826 - * one is good. 3827 - * 3828 - * Side effects: 3829 - * 3830 - * Call context: 3831 - *---------------------------------------------------------------- 3832 - */ 3833 - static int hfa384x_isgood_pdrcode(u16 pdrcode) 3834 - { 3835 - switch (pdrcode) { 3836 - case HFA384x_PDR_END_OF_PDA: 3837 - case HFA384x_PDR_PCB_PARTNUM: 3838 - case HFA384x_PDR_PDAVER: 3839 - case HFA384x_PDR_NIC_SERIAL: 3840 - case HFA384x_PDR_MKK_MEASUREMENTS: 3841 - case HFA384x_PDR_NIC_RAMSIZE: 3842 - case HFA384x_PDR_MFISUPRANGE: 3843 - case HFA384x_PDR_CFISUPRANGE: 3844 - case HFA384x_PDR_NICID: 3845 - case HFA384x_PDR_MAC_ADDRESS: 3846 - case HFA384x_PDR_REGDOMAIN: 3847 - case HFA384x_PDR_ALLOWED_CHANNEL: 3848 - case HFA384x_PDR_DEFAULT_CHANNEL: 3849 - case HFA384x_PDR_TEMPTYPE: 3850 - case HFA384x_PDR_IFR_SETTING: 3851 - case HFA384x_PDR_RFR_SETTING: 3852 - case HFA384x_PDR_HFA3861_BASELINE: 3853 - case HFA384x_PDR_HFA3861_SHADOW: 3854 - case HFA384x_PDR_HFA3861_IFRF: 3855 - case HFA384x_PDR_HFA3861_CHCALSP: 3856 - case HFA384x_PDR_HFA3861_CHCALI: 3857 - case HFA384x_PDR_3842_NIC_CONFIG: 3858 - case HFA384x_PDR_USB_ID: 3859 - case HFA384x_PDR_PCI_ID: 3860 - case HFA384x_PDR_PCI_IFCONF: 3861 - case HFA384x_PDR_PCI_PMCONF: 3862 - case HFA384x_PDR_RFENRGY: 3863 - case HFA384x_PDR_HFA3861_MANF_TESTSP: 3864 - case HFA384x_PDR_HFA3861_MANF_TESTI: 3865 - /* code is OK */ 3866 - return 1; 3867 - default: 3868 - if (pdrcode < 0x1000) { 3869 - /* code is OK, but we don't know exactly what it is */ 3870 - pr_debug("Encountered unknown PDR#=0x%04x, assuming it's ok.\n", 3871 - pdrcode); 3872 - return 1; 3873 - } 3874 - break; 3875 - } 3876 - /* bad code */ 3877 - pr_debug("Encountered unknown PDR#=0x%04x, (>=0x1000), assuming it's bad.\n", 3878 - pdrcode); 3879 - return 0; 3880 - }
-643
drivers/staging/wlan-ng/p80211conv.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Ether/802.11 conversions and packet buffer routines 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file defines the functions that perform Ethernet to/from 28 - * 802.11 frame conversions. 29 - * 30 - * -------------------------------------------------------------------- 31 - * 32 - *================================================================ 33 - */ 34 - 35 - #include <linux/module.h> 36 - #include <linux/kernel.h> 37 - #include <linux/sched.h> 38 - #include <linux/types.h> 39 - #include <linux/skbuff.h> 40 - #include <linux/slab.h> 41 - #include <linux/wireless.h> 42 - #include <linux/netdevice.h> 43 - #include <linux/etherdevice.h> 44 - #include <linux/if_ether.h> 45 - #include <linux/byteorder/generic.h> 46 - 47 - #include <asm/byteorder.h> 48 - 49 - #include "p80211types.h" 50 - #include "p80211hdr.h" 51 - #include "p80211conv.h" 52 - #include "p80211mgmt.h" 53 - #include "p80211msg.h" 54 - #include "p80211netdev.h" 55 - #include "p80211ioctl.h" 56 - #include "p80211req.h" 57 - 58 - static const u8 oui_rfc1042[] = { 0x00, 0x00, 0x00 }; 59 - static const u8 oui_8021h[] = { 0x00, 0x00, 0xf8 }; 60 - 61 - /*---------------------------------------------------------------- 62 - * p80211pb_ether_to_80211 63 - * 64 - * Uses the contents of the ether frame and the etherconv setting 65 - * to build the elements of the 802.11 frame. 66 - * 67 - * We don't actually set 68 - * up the frame header here. That's the MAC's job. We're only handling 69 - * conversion of DIXII or 802.3+LLC frames to something that works 70 - * with 802.11. 71 - * 72 - * Note -- 802.11 header is NOT part of the skb. Likewise, the 802.11 73 - * FCS is also not present and will need to be added elsewhere. 74 - * 75 - * Arguments: 76 - * ethconv Conversion type to perform 77 - * skb skbuff containing the ether frame 78 - * p80211_hdr 802.11 header 79 - * 80 - * Returns: 81 - * 0 on success, non-zero otherwise 82 - * 83 - * Call context: 84 - * May be called in interrupt or non-interrupt context 85 - *---------------------------------------------------------------- 86 - */ 87 - int skb_ether_to_p80211(struct wlandevice *wlandev, u32 ethconv, 88 - struct sk_buff *skb, struct p80211_hdr *p80211_hdr, 89 - struct p80211_metawep *p80211_wep) 90 - { 91 - __le16 fc; 92 - u16 proto; 93 - struct wlan_ethhdr e_hdr; 94 - struct wlan_llc *e_llc; 95 - struct wlan_snap *e_snap; 96 - int foo; 97 - 98 - memcpy(&e_hdr, skb->data, sizeof(e_hdr)); 99 - 100 - if (skb->len <= 0) { 101 - pr_debug("zero-length skb!\n"); 102 - return 1; 103 - } 104 - 105 - if (ethconv == WLAN_ETHCONV_ENCAP) { /* simplest case */ 106 - pr_debug("ENCAP len: %d\n", skb->len); 107 - /* here, we don't care what kind of ether frm. Just stick it */ 108 - /* in the 80211 payload */ 109 - /* which is to say, leave the skb alone. */ 110 - } else { 111 - /* step 1: classify ether frame, DIX or 802.3? */ 112 - proto = ntohs(e_hdr.type); 113 - if (proto <= ETH_DATA_LEN) { 114 - pr_debug("802.3 len: %d\n", skb->len); 115 - /* codes <= 1500 reserved for 802.3 lengths */ 116 - /* it's 802.3, pass ether payload unchanged, */ 117 - 118 - /* trim off ethernet header */ 119 - skb_pull(skb, ETH_HLEN); 120 - 121 - /* leave off any PAD octets. */ 122 - skb_trim(skb, proto); 123 - } else { 124 - pr_debug("DIXII len: %d\n", skb->len); 125 - /* it's DIXII, time for some conversion */ 126 - 127 - /* trim off ethernet header */ 128 - skb_pull(skb, ETH_HLEN); 129 - 130 - /* tack on SNAP */ 131 - e_snap = skb_push(skb, sizeof(struct wlan_snap)); 132 - e_snap->type = htons(proto); 133 - if (ethconv == WLAN_ETHCONV_8021h && 134 - p80211_stt_findproto(proto)) { 135 - memcpy(e_snap->oui, oui_8021h, 136 - WLAN_IEEE_OUI_LEN); 137 - } else { 138 - memcpy(e_snap->oui, oui_rfc1042, 139 - WLAN_IEEE_OUI_LEN); 140 - } 141 - 142 - /* tack on llc */ 143 - e_llc = skb_push(skb, sizeof(struct wlan_llc)); 144 - e_llc->dsap = 0xAA; /* SNAP, see IEEE 802 */ 145 - e_llc->ssap = 0xAA; 146 - e_llc->ctl = 0x03; 147 - } 148 - } 149 - 150 - /* Set up the 802.11 header */ 151 - /* It's a data frame */ 152 - fc = cpu_to_le16(WLAN_SET_FC_FTYPE(WLAN_FTYPE_DATA) | 153 - WLAN_SET_FC_FSTYPE(WLAN_FSTYPE_DATAONLY)); 154 - 155 - switch (wlandev->macmode) { 156 - case WLAN_MACMODE_IBSS_STA: 157 - memcpy(p80211_hdr->address1, &e_hdr.daddr, ETH_ALEN); 158 - memcpy(p80211_hdr->address2, wlandev->netdev->dev_addr, ETH_ALEN); 159 - memcpy(p80211_hdr->address3, wlandev->bssid, ETH_ALEN); 160 - break; 161 - case WLAN_MACMODE_ESS_STA: 162 - fc |= cpu_to_le16(WLAN_SET_FC_TODS(1)); 163 - memcpy(p80211_hdr->address1, wlandev->bssid, ETH_ALEN); 164 - memcpy(p80211_hdr->address2, wlandev->netdev->dev_addr, ETH_ALEN); 165 - memcpy(p80211_hdr->address3, &e_hdr.daddr, ETH_ALEN); 166 - break; 167 - case WLAN_MACMODE_ESS_AP: 168 - fc |= cpu_to_le16(WLAN_SET_FC_FROMDS(1)); 169 - memcpy(p80211_hdr->address1, &e_hdr.daddr, ETH_ALEN); 170 - memcpy(p80211_hdr->address2, wlandev->bssid, ETH_ALEN); 171 - memcpy(p80211_hdr->address3, &e_hdr.saddr, ETH_ALEN); 172 - break; 173 - default: 174 - netdev_err(wlandev->netdev, 175 - "Error: Converting eth to wlan in unknown mode.\n"); 176 - return 1; 177 - } 178 - 179 - p80211_wep->data = NULL; 180 - 181 - if ((wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) && 182 - (wlandev->hostwep & HOSTWEP_ENCRYPT)) { 183 - /* XXXX need to pick keynum other than default? */ 184 - 185 - p80211_wep->data = kmalloc(skb->len, GFP_ATOMIC); 186 - if (!p80211_wep->data) 187 - return -ENOMEM; 188 - foo = wep_encrypt(wlandev, skb->data, p80211_wep->data, 189 - skb->len, 190 - wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK, 191 - p80211_wep->iv, p80211_wep->icv); 192 - if (foo) { 193 - netdev_warn(wlandev->netdev, 194 - "Host en-WEP failed, dropping frame (%d).\n", 195 - foo); 196 - kfree(p80211_wep->data); 197 - return 2; 198 - } 199 - fc |= cpu_to_le16(WLAN_SET_FC_ISWEP(1)); 200 - } 201 - 202 - /* skb->nh.raw = skb->data; */ 203 - 204 - p80211_hdr->frame_control = fc; 205 - p80211_hdr->duration_id = 0; 206 - p80211_hdr->sequence_control = 0; 207 - 208 - return 0; 209 - } 210 - 211 - /* jkriegl: from orinoco, modified */ 212 - static void orinoco_spy_gather(struct wlandevice *wlandev, char *mac, 213 - struct p80211_rxmeta *rxmeta) 214 - { 215 - int i; 216 - 217 - /* Gather wireless spy statistics: for each packet, compare the 218 - * source address with out list, and if match, get the stats... 219 - */ 220 - 221 - for (i = 0; i < wlandev->spy_number; i++) { 222 - if (!memcmp(wlandev->spy_address[i], mac, ETH_ALEN)) { 223 - wlandev->spy_stat[i].level = rxmeta->signal; 224 - wlandev->spy_stat[i].noise = rxmeta->noise; 225 - wlandev->spy_stat[i].qual = 226 - (rxmeta->signal > 227 - rxmeta->noise) ? (rxmeta->signal - 228 - rxmeta->noise) : 0; 229 - wlandev->spy_stat[i].updated = 0x7; 230 - } 231 - } 232 - } 233 - 234 - /*---------------------------------------------------------------- 235 - * p80211pb_80211_to_ether 236 - * 237 - * Uses the contents of a received 802.11 frame and the etherconv 238 - * setting to build an ether frame. 239 - * 240 - * This function extracts the src and dest address from the 802.11 241 - * frame to use in the construction of the eth frame. 242 - * 243 - * Arguments: 244 - * ethconv Conversion type to perform 245 - * skb Packet buffer containing the 802.11 frame 246 - * 247 - * Returns: 248 - * 0 on success, non-zero otherwise 249 - * 250 - * Call context: 251 - * May be called in interrupt or non-interrupt context 252 - *---------------------------------------------------------------- 253 - */ 254 - int skb_p80211_to_ether(struct wlandevice *wlandev, u32 ethconv, 255 - struct sk_buff *skb) 256 - { 257 - struct net_device *netdev = wlandev->netdev; 258 - u16 fc; 259 - unsigned int payload_length; 260 - unsigned int payload_offset; 261 - u8 daddr[ETH_ALEN]; 262 - u8 saddr[ETH_ALEN]; 263 - struct p80211_hdr *w_hdr; 264 - struct wlan_ethhdr *e_hdr; 265 - struct wlan_llc *e_llc; 266 - struct wlan_snap *e_snap; 267 - 268 - int foo; 269 - 270 - payload_length = skb->len - WLAN_HDR_A3_LEN - WLAN_CRC_LEN; 271 - payload_offset = WLAN_HDR_A3_LEN; 272 - 273 - w_hdr = (struct p80211_hdr *)skb->data; 274 - 275 - /* setup some vars for convenience */ 276 - fc = le16_to_cpu(w_hdr->frame_control); 277 - if ((WLAN_GET_FC_TODS(fc) == 0) && (WLAN_GET_FC_FROMDS(fc) == 0)) { 278 - ether_addr_copy(daddr, w_hdr->address1); 279 - ether_addr_copy(saddr, w_hdr->address2); 280 - } else if ((WLAN_GET_FC_TODS(fc) == 0) && 281 - (WLAN_GET_FC_FROMDS(fc) == 1)) { 282 - ether_addr_copy(daddr, w_hdr->address1); 283 - ether_addr_copy(saddr, w_hdr->address3); 284 - } else if ((WLAN_GET_FC_TODS(fc) == 1) && 285 - (WLAN_GET_FC_FROMDS(fc) == 0)) { 286 - ether_addr_copy(daddr, w_hdr->address3); 287 - ether_addr_copy(saddr, w_hdr->address2); 288 - } else { 289 - payload_offset = WLAN_HDR_A4_LEN; 290 - if (payload_length < WLAN_HDR_A4_LEN - WLAN_HDR_A3_LEN) { 291 - netdev_err(netdev, "A4 frame too short!\n"); 292 - return 1; 293 - } 294 - payload_length -= (WLAN_HDR_A4_LEN - WLAN_HDR_A3_LEN); 295 - ether_addr_copy(daddr, w_hdr->address3); 296 - ether_addr_copy(saddr, w_hdr->address4); 297 - } 298 - 299 - /* perform de-wep if necessary.. */ 300 - if ((wlandev->hostwep & HOSTWEP_PRIVACYINVOKED) && 301 - WLAN_GET_FC_ISWEP(fc) && 302 - (wlandev->hostwep & HOSTWEP_DECRYPT)) { 303 - if (payload_length <= 8) { 304 - netdev_err(netdev, 305 - "WEP frame too short (%u).\n", skb->len); 306 - return 1; 307 - } 308 - foo = wep_decrypt(wlandev, skb->data + payload_offset + 4, 309 - payload_length - 8, -1, 310 - skb->data + payload_offset, 311 - skb->data + payload_offset + 312 - payload_length - 4); 313 - if (foo) { 314 - /* de-wep failed, drop skb. */ 315 - netdev_dbg(netdev, "Host de-WEP failed, dropping frame (%d).\n", 316 - foo); 317 - wlandev->rx.decrypt_err++; 318 - return 2; 319 - } 320 - 321 - /* subtract the IV+ICV length off the payload */ 322 - payload_length -= 8; 323 - /* chop off the IV */ 324 - skb_pull(skb, 4); 325 - /* chop off the ICV. */ 326 - skb_trim(skb, skb->len - 4); 327 - 328 - wlandev->rx.decrypt++; 329 - } 330 - 331 - e_hdr = (struct wlan_ethhdr *)(skb->data + payload_offset); 332 - 333 - e_llc = (struct wlan_llc *)(skb->data + payload_offset); 334 - e_snap = 335 - (struct wlan_snap *)(skb->data + payload_offset + 336 - sizeof(struct wlan_llc)); 337 - 338 - /* Test for the various encodings */ 339 - if ((payload_length >= sizeof(struct wlan_ethhdr)) && 340 - (e_llc->dsap != 0xaa || e_llc->ssap != 0xaa) && 341 - ((!ether_addr_equal_unaligned(daddr, e_hdr->daddr)) || 342 - (!ether_addr_equal_unaligned(saddr, e_hdr->saddr)))) { 343 - netdev_dbg(netdev, "802.3 ENCAP len: %d\n", payload_length); 344 - /* 802.3 Encapsulated */ 345 - /* Test for an overlength frame */ 346 - if (payload_length > (netdev->mtu + ETH_HLEN)) { 347 - /* A bogus length ethfrm has been encap'd. */ 348 - /* Is someone trying an oflow attack? */ 349 - netdev_err(netdev, "ENCAP frame too large (%d > %d)\n", 350 - payload_length, netdev->mtu + ETH_HLEN); 351 - return 1; 352 - } 353 - 354 - /* Chop off the 802.11 header. it's already sane. */ 355 - skb_pull(skb, payload_offset); 356 - /* chop off the 802.11 CRC */ 357 - skb_trim(skb, skb->len - WLAN_CRC_LEN); 358 - 359 - } else if ((payload_length >= sizeof(struct wlan_llc) + 360 - sizeof(struct wlan_snap)) && 361 - (e_llc->dsap == 0xaa) && 362 - (e_llc->ssap == 0xaa) && 363 - (e_llc->ctl == 0x03) && 364 - (((memcmp(e_snap->oui, oui_rfc1042, 365 - WLAN_IEEE_OUI_LEN) == 0) && 366 - (ethconv == WLAN_ETHCONV_8021h) && 367 - (p80211_stt_findproto(be16_to_cpu(e_snap->type)))) || 368 - (memcmp(e_snap->oui, oui_rfc1042, WLAN_IEEE_OUI_LEN) != 369 - 0))) { 370 - netdev_dbg(netdev, "SNAP+RFC1042 len: %d\n", payload_length); 371 - /* it's a SNAP + RFC1042 frame && protocol is in STT */ 372 - /* build 802.3 + RFC1042 */ 373 - 374 - /* Test for an overlength frame */ 375 - if (payload_length > netdev->mtu) { 376 - /* A bogus length ethfrm has been sent. */ 377 - /* Is someone trying an oflow attack? */ 378 - netdev_err(netdev, "SNAP frame too large (%d > %d)\n", 379 - payload_length, netdev->mtu); 380 - return 1; 381 - } 382 - 383 - /* chop 802.11 header from skb. */ 384 - skb_pull(skb, payload_offset); 385 - 386 - /* create 802.3 header at beginning of skb. */ 387 - e_hdr = skb_push(skb, ETH_HLEN); 388 - ether_addr_copy(e_hdr->daddr, daddr); 389 - ether_addr_copy(e_hdr->saddr, saddr); 390 - e_hdr->type = htons(payload_length); 391 - 392 - /* chop off the 802.11 CRC */ 393 - skb_trim(skb, skb->len - WLAN_CRC_LEN); 394 - 395 - } else if ((payload_length >= sizeof(struct wlan_llc) + 396 - sizeof(struct wlan_snap)) && 397 - (e_llc->dsap == 0xaa) && 398 - (e_llc->ssap == 0xaa) && 399 - (e_llc->ctl == 0x03)) { 400 - netdev_dbg(netdev, "802.1h/RFC1042 len: %d\n", payload_length); 401 - /* it's an 802.1h frame || (an RFC1042 && protocol not in STT) 402 - * build a DIXII + RFC894 403 - */ 404 - 405 - /* Test for an overlength frame */ 406 - if ((payload_length - sizeof(struct wlan_llc) - 407 - sizeof(struct wlan_snap)) 408 - > netdev->mtu) { 409 - /* A bogus length ethfrm has been sent. */ 410 - /* Is someone trying an oflow attack? */ 411 - netdev_err(netdev, "DIXII frame too large (%ld > %d)\n", 412 - (long)(payload_length - 413 - sizeof(struct wlan_llc) - 414 - sizeof(struct wlan_snap)), netdev->mtu); 415 - return 1; 416 - } 417 - 418 - /* chop 802.11 header from skb. */ 419 - skb_pull(skb, payload_offset); 420 - 421 - /* chop llc header from skb. */ 422 - skb_pull(skb, sizeof(struct wlan_llc)); 423 - 424 - /* chop snap header from skb. */ 425 - skb_pull(skb, sizeof(struct wlan_snap)); 426 - 427 - /* create 802.3 header at beginning of skb. */ 428 - e_hdr = skb_push(skb, ETH_HLEN); 429 - e_hdr->type = e_snap->type; 430 - ether_addr_copy(e_hdr->daddr, daddr); 431 - ether_addr_copy(e_hdr->saddr, saddr); 432 - 433 - /* chop off the 802.11 CRC */ 434 - skb_trim(skb, skb->len - WLAN_CRC_LEN); 435 - } else { 436 - netdev_dbg(netdev, "NON-ENCAP len: %d\n", payload_length); 437 - /* any NON-ENCAP */ 438 - /* it's a generic 80211+LLC or IPX 'Raw 802.3' */ 439 - /* build an 802.3 frame */ 440 - /* allocate space and setup hostbuf */ 441 - 442 - /* Test for an overlength frame */ 443 - if (payload_length > netdev->mtu) { 444 - /* A bogus length ethfrm has been sent. */ 445 - /* Is someone trying an oflow attack? */ 446 - netdev_err(netdev, "OTHER frame too large (%d > %d)\n", 447 - payload_length, netdev->mtu); 448 - return 1; 449 - } 450 - 451 - /* Chop off the 802.11 header. */ 452 - skb_pull(skb, payload_offset); 453 - 454 - /* create 802.3 header at beginning of skb. */ 455 - e_hdr = skb_push(skb, ETH_HLEN); 456 - ether_addr_copy(e_hdr->daddr, daddr); 457 - ether_addr_copy(e_hdr->saddr, saddr); 458 - e_hdr->type = htons(payload_length); 459 - 460 - /* chop off the 802.11 CRC */ 461 - skb_trim(skb, skb->len - WLAN_CRC_LEN); 462 - } 463 - 464 - /* 465 - * Note that eth_type_trans() expects an skb w/ skb->data pointing 466 - * at the MAC header, it then sets the following skb members: 467 - * skb->mac_header, 468 - * skb->data, and 469 - * skb->pkt_type. 470 - * It then _returns_ the value that _we're_ supposed to stuff in 471 - * skb->protocol. This is nuts. 472 - */ 473 - skb->protocol = eth_type_trans(skb, netdev); 474 - 475 - /* jkriegl: process signal and noise as set in hfa384x_int_rx() */ 476 - /* jkriegl: only process signal/noise if requested by iwspy */ 477 - if (wlandev->spy_number) 478 - orinoco_spy_gather(wlandev, eth_hdr(skb)->h_source, 479 - p80211skb_rxmeta(skb)); 480 - 481 - /* Free the metadata */ 482 - p80211skb_rxmeta_detach(skb); 483 - 484 - return 0; 485 - } 486 - 487 - /*---------------------------------------------------------------- 488 - * p80211_stt_findproto 489 - * 490 - * Searches the 802.1h Selective Translation Table for a given 491 - * protocol. 492 - * 493 - * Arguments: 494 - * proto protocol number (in host order) to search for. 495 - * 496 - * Returns: 497 - * 1 - if the table is empty or a match is found. 498 - * 0 - if the table is non-empty and a match is not found. 499 - * 500 - * Call context: 501 - * May be called in interrupt or non-interrupt context 502 - *---------------------------------------------------------------- 503 - */ 504 - int p80211_stt_findproto(u16 proto) 505 - { 506 - /* Always return found for now. This is the behavior used by the */ 507 - /* Zoom Win95 driver when 802.1h mode is selected */ 508 - /* TODO: If necessary, add an actual search we'll probably 509 - * need this to match the CMAC's way of doing things. 510 - * Need to do some testing to confirm. 511 - */ 512 - 513 - if (proto == ETH_P_AARP) /* APPLETALK */ 514 - return 1; 515 - 516 - return 0; 517 - } 518 - 519 - /*---------------------------------------------------------------- 520 - * p80211skb_rxmeta_detach 521 - * 522 - * Disconnects the frmmeta and rxmeta from an skb. 523 - * 524 - * Arguments: 525 - * wlandev The wlandev this skb belongs to. 526 - * skb The skb we're attaching to. 527 - * 528 - * Returns: 529 - * 0 on success, non-zero otherwise 530 - * 531 - * Call context: 532 - * May be called in interrupt or non-interrupt context 533 - *---------------------------------------------------------------- 534 - */ 535 - void p80211skb_rxmeta_detach(struct sk_buff *skb) 536 - { 537 - struct p80211_rxmeta *rxmeta; 538 - struct p80211_frmmeta *frmmeta; 539 - 540 - /* Sanity checks */ 541 - if (!skb) { /* bad skb */ 542 - pr_debug("Called w/ null skb.\n"); 543 - return; 544 - } 545 - frmmeta = p80211skb_frmmeta(skb); 546 - if (!frmmeta) { /* no magic */ 547 - pr_debug("Called w/ bad frmmeta magic.\n"); 548 - return; 549 - } 550 - rxmeta = frmmeta->rx; 551 - if (!rxmeta) { /* bad meta ptr */ 552 - pr_debug("Called w/ bad rxmeta ptr.\n"); 553 - return; 554 - } 555 - 556 - /* Free rxmeta */ 557 - kfree(rxmeta); 558 - 559 - /* Clear skb->cb */ 560 - memset(skb->cb, 0, sizeof(skb->cb)); 561 - } 562 - 563 - /*---------------------------------------------------------------- 564 - * p80211skb_rxmeta_attach 565 - * 566 - * Allocates a p80211rxmeta structure, initializes it, and attaches 567 - * it to an skb. 568 - * 569 - * Arguments: 570 - * wlandev The wlandev this skb belongs to. 571 - * skb The skb we're attaching to. 572 - * 573 - * Returns: 574 - * 0 on success, non-zero otherwise 575 - * 576 - * Call context: 577 - * May be called in interrupt or non-interrupt context 578 - *---------------------------------------------------------------- 579 - */ 580 - int p80211skb_rxmeta_attach(struct wlandevice *wlandev, struct sk_buff *skb) 581 - { 582 - int result = 0; 583 - struct p80211_rxmeta *rxmeta; 584 - struct p80211_frmmeta *frmmeta; 585 - 586 - /* If these already have metadata, we error out! */ 587 - if (p80211skb_rxmeta(skb)) { 588 - netdev_err(wlandev->netdev, 589 - "%s: RXmeta already attached!\n", wlandev->name); 590 - result = 0; 591 - goto exit; 592 - } 593 - 594 - /* Allocate the rxmeta */ 595 - rxmeta = kzalloc(sizeof(*rxmeta), GFP_ATOMIC); 596 - 597 - if (!rxmeta) { 598 - result = 1; 599 - goto exit; 600 - } 601 - 602 - /* Initialize the rxmeta */ 603 - rxmeta->wlandev = wlandev; 604 - rxmeta->hosttime = jiffies; 605 - 606 - /* Overlay a frmmeta_t onto skb->cb */ 607 - memset(skb->cb, 0, sizeof(struct p80211_frmmeta)); 608 - frmmeta = (struct p80211_frmmeta *)(skb->cb); 609 - frmmeta->magic = P80211_FRMMETA_MAGIC; 610 - frmmeta->rx = rxmeta; 611 - exit: 612 - return result; 613 - } 614 - 615 - /*---------------------------------------------------------------- 616 - * p80211skb_free 617 - * 618 - * Frees an entire p80211skb by checking and freeing the meta struct 619 - * and then freeing the skb. 620 - * 621 - * Arguments: 622 - * wlandev The wlandev this skb belongs to. 623 - * skb The skb we're attaching to. 624 - * 625 - * Returns: 626 - * 0 on success, non-zero otherwise 627 - * 628 - * Call context: 629 - * May be called in interrupt or non-interrupt context 630 - *---------------------------------------------------------------- 631 - */ 632 - void p80211skb_free(struct wlandevice *wlandev, struct sk_buff *skb) 633 - { 634 - struct p80211_frmmeta *meta; 635 - 636 - meta = p80211skb_frmmeta(skb); 637 - if (meta && meta->rx) 638 - p80211skb_rxmeta_detach(skb); 639 - else 640 - netdev_err(wlandev->netdev, 641 - "Freeing an skb (%p) w/ no frmmeta.\n", skb); 642 - dev_kfree_skb(skb); 643 - }
-141
drivers/staging/wlan-ng/p80211conv.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Ether/802.11 conversions and packet buffer routines 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file declares the functions, types and macros that perform 28 - * Ethernet to/from 802.11 frame conversions. 29 - * 30 - * -------------------------------------------------------------------- 31 - */ 32 - 33 - #ifndef _LINUX_P80211CONV_H 34 - #define _LINUX_P80211CONV_H 35 - 36 - #define WLAN_IEEE_OUI_LEN 3 37 - 38 - #define WLAN_ETHCONV_ENCAP 1 39 - #define WLAN_ETHCONV_8021h 3 40 - 41 - #define P80211CAPTURE_VERSION 0x80211001 42 - 43 - #define P80211_FRMMETA_MAGIC 0x802110 44 - 45 - struct p80211_rxmeta { 46 - struct wlandevice *wlandev; 47 - 48 - u64 mactime; /* Hi-rez MAC-supplied time value */ 49 - u64 hosttime; /* Best-rez host supplied time value */ 50 - 51 - unsigned int rxrate; /* Receive data rate in 100kbps */ 52 - unsigned int priority; /* 0-15, 0=contention, 6=CF */ 53 - int signal; /* An SSI, see p80211netdev.h */ 54 - int noise; /* An SSI, see p80211netdev.h */ 55 - unsigned int channel; /* Receive channel (mostly for snifs) */ 56 - unsigned int preamble; /* P80211ENUM_preambletype_* */ 57 - unsigned int encoding; /* P80211ENUM_encoding_* */ 58 - 59 - }; 60 - 61 - struct p80211_frmmeta { 62 - unsigned int magic; 63 - struct p80211_rxmeta *rx; 64 - }; 65 - 66 - void p80211skb_free(struct wlandevice *wlandev, struct sk_buff *skb); 67 - int p80211skb_rxmeta_attach(struct wlandevice *wlandev, struct sk_buff *skb); 68 - void p80211skb_rxmeta_detach(struct sk_buff *skb); 69 - 70 - static inline struct p80211_frmmeta *p80211skb_frmmeta(struct sk_buff *skb) 71 - { 72 - struct p80211_frmmeta *frmmeta = (struct p80211_frmmeta *)skb->cb; 73 - 74 - return frmmeta->magic == P80211_FRMMETA_MAGIC ? frmmeta : NULL; 75 - } 76 - 77 - static inline struct p80211_rxmeta *p80211skb_rxmeta(struct sk_buff *skb) 78 - { 79 - struct p80211_frmmeta *frmmeta = p80211skb_frmmeta(skb); 80 - 81 - return frmmeta ? frmmeta->rx : NULL; 82 - } 83 - 84 - /* 85 - * Frame capture header. (See doc/capturefrm.txt) 86 - */ 87 - struct p80211_caphdr { 88 - __be32 version; 89 - __be32 length; 90 - __be64 mactime; 91 - __be64 hosttime; 92 - __be32 phytype; 93 - __be32 channel; 94 - __be32 datarate; 95 - __be32 antenna; 96 - __be32 priority; 97 - __be32 ssi_type; 98 - __be32 ssi_signal; 99 - __be32 ssi_noise; 100 - __be32 preamble; 101 - __be32 encoding; 102 - }; 103 - 104 - struct p80211_metawep { 105 - void *data; 106 - u8 iv[4]; 107 - u8 icv[4]; 108 - }; 109 - 110 - /* local ether header type */ 111 - struct wlan_ethhdr { 112 - u8 daddr[ETH_ALEN]; 113 - u8 saddr[ETH_ALEN]; 114 - __be16 type; 115 - } __packed; 116 - 117 - /* local llc header type */ 118 - struct wlan_llc { 119 - u8 dsap; 120 - u8 ssap; 121 - u8 ctl; 122 - } __packed; 123 - 124 - /* local snap header type */ 125 - struct wlan_snap { 126 - u8 oui[WLAN_IEEE_OUI_LEN]; 127 - __be16 type; 128 - } __packed; 129 - 130 - /* Circular include trick */ 131 - struct wlandevice; 132 - 133 - int skb_p80211_to_ether(struct wlandevice *wlandev, u32 ethconv, 134 - struct sk_buff *skb); 135 - int skb_ether_to_p80211(struct wlandevice *wlandev, u32 ethconv, 136 - struct sk_buff *skb, struct p80211_hdr *p80211_hdr, 137 - struct p80211_metawep *p80211_wep); 138 - 139 - int p80211_stt_findproto(u16 proto); 140 - 141 - #endif
-189
drivers/staging/wlan-ng/p80211hdr.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Macros, types, and functions for handling 802.11 MAC headers 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file declares the constants and types used in the interface 28 - * between a wlan driver and the user mode utilities. 29 - * 30 - * Note: 31 - * - Constant values are always in HOST byte order. To assign 32 - * values to multi-byte fields they _must_ be converted to 33 - * ieee byte order. To retrieve multi-byte values from incoming 34 - * frames, they must be converted to host order. 35 - * 36 - * All functions declared here are implemented in p80211.c 37 - * -------------------------------------------------------------------- 38 - */ 39 - 40 - #ifndef _P80211HDR_H 41 - #define _P80211HDR_H 42 - 43 - #include <linux/if_ether.h> 44 - 45 - /*--- Sizes -----------------------------------------------*/ 46 - #define WLAN_CRC_LEN 4 47 - #define WLAN_BSSID_LEN 6 48 - #define WLAN_HDR_A3_LEN 24 49 - #define WLAN_HDR_A4_LEN 30 50 - #define WLAN_SSID_MAXLEN 32 51 - #define WLAN_DATA_MAXLEN 2312 52 - #define WLAN_WEP_IV_LEN 4 53 - #define WLAN_WEP_ICV_LEN 4 54 - 55 - /*--- Frame Control Field -------------------------------------*/ 56 - /* Frame Types */ 57 - #define WLAN_FTYPE_MGMT 0x00 58 - #define WLAN_FTYPE_CTL 0x01 59 - #define WLAN_FTYPE_DATA 0x02 60 - 61 - /* Frame subtypes */ 62 - /* Management */ 63 - #define WLAN_FSTYPE_ASSOCREQ 0x00 64 - #define WLAN_FSTYPE_ASSOCRESP 0x01 65 - #define WLAN_FSTYPE_REASSOCREQ 0x02 66 - #define WLAN_FSTYPE_REASSOCRESP 0x03 67 - #define WLAN_FSTYPE_PROBEREQ 0x04 68 - #define WLAN_FSTYPE_PROBERESP 0x05 69 - #define WLAN_FSTYPE_BEACON 0x08 70 - #define WLAN_FSTYPE_ATIM 0x09 71 - #define WLAN_FSTYPE_DISASSOC 0x0a 72 - #define WLAN_FSTYPE_AUTHEN 0x0b 73 - #define WLAN_FSTYPE_DEAUTHEN 0x0c 74 - 75 - /* Control */ 76 - #define WLAN_FSTYPE_BLOCKACKREQ 0x8 77 - #define WLAN_FSTYPE_BLOCKACK 0x9 78 - #define WLAN_FSTYPE_PSPOLL 0x0a 79 - #define WLAN_FSTYPE_RTS 0x0b 80 - #define WLAN_FSTYPE_CTS 0x0c 81 - #define WLAN_FSTYPE_ACK 0x0d 82 - #define WLAN_FSTYPE_CFEND 0x0e 83 - #define WLAN_FSTYPE_CFENDCFACK 0x0f 84 - 85 - /* Data */ 86 - #define WLAN_FSTYPE_DATAONLY 0x00 87 - #define WLAN_FSTYPE_DATA_CFACK 0x01 88 - #define WLAN_FSTYPE_DATA_CFPOLL 0x02 89 - #define WLAN_FSTYPE_DATA_CFACK_CFPOLL 0x03 90 - #define WLAN_FSTYPE_NULL 0x04 91 - #define WLAN_FSTYPE_CFACK 0x05 92 - #define WLAN_FSTYPE_CFPOLL 0x06 93 - #define WLAN_FSTYPE_CFACK_CFPOLL 0x07 94 - 95 - /*--- FC Macros ----------------------------------------------*/ 96 - /* Macros to get/set the bitfields of the Frame Control Field */ 97 - /* GET_FC_??? - takes the host byte-order value of an FC */ 98 - /* and retrieves the value of one of the */ 99 - /* bitfields and moves that value so its lsb is */ 100 - /* in bit 0. */ 101 - /* SET_FC_??? - takes a host order value for one of the FC */ 102 - /* bitfields and moves it to the proper bit */ 103 - /* location for ORing into a host order FC. */ 104 - /* To send the FC produced from SET_FC_???, */ 105 - /* one must put the bytes in IEEE order. */ 106 - /* e.g. */ 107 - /* printf("the frame subtype is %x", */ 108 - /* GET_FC_FTYPE( ieee2host( rx.fc ))) */ 109 - /* */ 110 - /* tx.fc = host2ieee( SET_FC_FTYPE(WLAN_FTYP_CTL) | */ 111 - /* SET_FC_FSTYPE(WLAN_FSTYPE_RTS) ); */ 112 - /*------------------------------------------------------------*/ 113 - 114 - #define WLAN_GET_FC_FTYPE(n) ((((u16)(n)) & GENMASK(3, 2)) >> 2) 115 - #define WLAN_GET_FC_FSTYPE(n) ((((u16)(n)) & GENMASK(7, 4)) >> 4) 116 - #define WLAN_GET_FC_TODS(n) ((((u16)(n)) & (BIT(8))) >> 8) 117 - #define WLAN_GET_FC_FROMDS(n) ((((u16)(n)) & (BIT(9))) >> 9) 118 - #define WLAN_GET_FC_ISWEP(n) ((((u16)(n)) & (BIT(14))) >> 14) 119 - 120 - #define WLAN_SET_FC_FTYPE(n) (((u16)(n)) << 2) 121 - #define WLAN_SET_FC_FSTYPE(n) (((u16)(n)) << 4) 122 - #define WLAN_SET_FC_TODS(n) (((u16)(n)) << 8) 123 - #define WLAN_SET_FC_FROMDS(n) (((u16)(n)) << 9) 124 - #define WLAN_SET_FC_ISWEP(n) (((u16)(n)) << 14) 125 - 126 - #define DOT11_RATE5_ISBASIC_GET(r) (((u8)(r)) & BIT(7)) 127 - 128 - /* Generic 802.11 Header types */ 129 - 130 - struct p80211_hdr { 131 - __le16 frame_control; 132 - u16 duration_id; 133 - u8 address1[ETH_ALEN]; 134 - u8 address2[ETH_ALEN]; 135 - u8 address3[ETH_ALEN]; 136 - u16 sequence_control; 137 - u8 address4[ETH_ALEN]; 138 - } __packed; 139 - 140 - /* Frame and header length macros */ 141 - 142 - static inline u16 wlan_ctl_framelen(u16 fstype) 143 - { 144 - switch (fstype) { 145 - case WLAN_FSTYPE_BLOCKACKREQ: 146 - return 24; 147 - case WLAN_FSTYPE_BLOCKACK: 148 - return 152; 149 - case WLAN_FSTYPE_PSPOLL: 150 - case WLAN_FSTYPE_RTS: 151 - case WLAN_FSTYPE_CFEND: 152 - case WLAN_FSTYPE_CFENDCFACK: 153 - return 20; 154 - case WLAN_FSTYPE_CTS: 155 - case WLAN_FSTYPE_ACK: 156 - return 14; 157 - default: 158 - return 4; 159 - } 160 - } 161 - 162 - #define WLAN_FCS_LEN 4 163 - 164 - /* ftcl in HOST order */ 165 - static inline u16 p80211_headerlen(u16 fctl) 166 - { 167 - u16 hdrlen = 0; 168 - 169 - switch (WLAN_GET_FC_FTYPE(fctl)) { 170 - case WLAN_FTYPE_MGMT: 171 - hdrlen = WLAN_HDR_A3_LEN; 172 - break; 173 - case WLAN_FTYPE_DATA: 174 - hdrlen = WLAN_HDR_A3_LEN; 175 - if (WLAN_GET_FC_TODS(fctl) && WLAN_GET_FC_FROMDS(fctl)) 176 - hdrlen += ETH_ALEN; 177 - break; 178 - case WLAN_FTYPE_CTL: 179 - hdrlen = wlan_ctl_framelen(WLAN_GET_FC_FSTYPE(fctl)) - 180 - WLAN_FCS_LEN; 181 - break; 182 - default: 183 - hdrlen = WLAN_HDR_A3_LEN; 184 - } 185 - 186 - return hdrlen; 187 - } 188 - 189 - #endif /* _P80211HDR_H */
-69
drivers/staging/wlan-ng/p80211ioctl.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Declares constants and types for the p80211 ioctls 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * While this file is called 'ioctl' is purpose goes a little beyond 28 - * that. This file defines the types and contants used to implement 29 - * the p80211 request/confirm/indicate interfaces on Linux. The 30 - * request/confirm interface is, in fact, normally implemented as an 31 - * ioctl. The indicate interface on the other hand, is implemented 32 - * using the Linux 'netlink' interface. 33 - * 34 - * The reason I say that request/confirm is 'normally' implemented 35 - * via ioctl is that we're reserving the right to be able to send 36 - * request commands via the netlink interface. This will be necessary 37 - * if we ever need to send request messages when there aren't any 38 - * wlan network devices present (i.e. sending a message that only p80211 39 - * cares about. 40 - * -------------------------------------------------------------------- 41 - */ 42 - 43 - #ifndef _P80211IOCTL_H 44 - #define _P80211IOCTL_H 45 - 46 - /* p80211 ioctl "request" codes. See argument 2 of ioctl(2). */ 47 - 48 - #define P80211_IFTEST (SIOCDEVPRIVATE + 0) 49 - #define P80211_IFREQ (SIOCDEVPRIVATE + 1) 50 - 51 - /*----------------------------------------------------------------*/ 52 - /* Magic number, a quick test to see we're getting the desired struct */ 53 - 54 - #define P80211_IOCTL_MAGIC (0x4a2d464dUL) 55 - 56 - /*----------------------------------------------------------------*/ 57 - /* A ptr to the following structure type is passed as the third */ 58 - /* argument to the ioctl system call when issuing a request to */ 59 - /* the p80211 module. */ 60 - 61 - struct p80211ioctl_req { 62 - char name[WLAN_DEVNAMELEN_MAX]; 63 - char __user *data; 64 - u32 magic; 65 - u16 len; 66 - u32 result; 67 - } __packed; 68 - 69 - #endif /* _P80211IOCTL_H */
-227
drivers/staging/wlan-ng/p80211metadef.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* -------------------------------------------------------------------- 3 - * 4 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 5 - * -------------------------------------------------------------------- 6 - * 7 - * linux-wlan 8 - * 9 - * -------------------------------------------------------------------- 10 - * 11 - * Inquiries regarding the linux-wlan Open Source project can be 12 - * made directly to: 13 - * 14 - * AbsoluteValue Systems Inc. 15 - * info@linux-wlan.com 16 - * http://www.linux-wlan.com 17 - * 18 - * -------------------------------------------------------------------- 19 - * 20 - * Portions of the development of this software were funded by 21 - * Intersil Corporation as part of PRISM(R) chipset product development. 22 - * 23 - * -------------------------------------------------------------------- 24 - */ 25 - 26 - #ifndef _P80211MKMETADEF_H 27 - #define _P80211MKMETADEF_H 28 - 29 - #define DIDMSG_DOT11REQ_MIBGET \ 30 - (P80211DID_MKSECTION(1) | \ 31 - P80211DID_MKGROUP(1)) 32 - #define DIDMSG_DOT11REQ_MIBGET_MIBATTRIBUTE \ 33 - (P80211DID_MKSECTION(1) | \ 34 - P80211DID_MKGROUP(1) | \ 35 - P80211DID_MKITEM(1) | 0x00000000) 36 - #define DIDMSG_DOT11REQ_MIBGET_RESULTCODE \ 37 - (P80211DID_MKSECTION(1) | \ 38 - P80211DID_MKGROUP(1) | \ 39 - P80211DID_MKITEM(2) | 0x00000000) 40 - #define DIDMSG_DOT11REQ_MIBSET \ 41 - (P80211DID_MKSECTION(1) | \ 42 - P80211DID_MKGROUP(2)) 43 - #define DIDMSG_DOT11REQ_MIBSET_MIBATTRIBUTE \ 44 - (P80211DID_MKSECTION(1) | \ 45 - P80211DID_MKGROUP(2) | \ 46 - P80211DID_MKITEM(1) | 0x00000000) 47 - #define DIDMSG_DOT11REQ_MIBSET_RESULTCODE \ 48 - (P80211DID_MKSECTION(1) | \ 49 - P80211DID_MKGROUP(2) | \ 50 - P80211DID_MKITEM(2) | 0x00000000) 51 - #define DIDMSG_DOT11REQ_SCAN \ 52 - (P80211DID_MKSECTION(1) | \ 53 - P80211DID_MKGROUP(4)) 54 - #define DIDMSG_DOT11REQ_SCAN_RESULTS \ 55 - (P80211DID_MKSECTION(1) | \ 56 - P80211DID_MKGROUP(5)) 57 - #define DIDMSG_DOT11REQ_START \ 58 - (P80211DID_MKSECTION(1) | \ 59 - P80211DID_MKGROUP(13)) 60 - #define DIDMSG_DOT11IND_AUTHENTICATE \ 61 - (P80211DID_MKSECTION(2) | \ 62 - P80211DID_MKGROUP(1)) 63 - #define DIDMSG_DOT11IND_ASSOCIATE \ 64 - (P80211DID_MKSECTION(2) | \ 65 - P80211DID_MKGROUP(3)) 66 - #define DIDMSG_LNXREQ_IFSTATE \ 67 - (P80211DID_MKSECTION(3) | \ 68 - P80211DID_MKGROUP(1)) 69 - #define DIDMSG_LNXREQ_WLANSNIFF \ 70 - (P80211DID_MKSECTION(3) | \ 71 - P80211DID_MKGROUP(2)) 72 - #define DIDMSG_LNXREQ_HOSTWEP \ 73 - (P80211DID_MKSECTION(3) | \ 74 - P80211DID_MKGROUP(3)) 75 - #define DIDMSG_LNXREQ_COMMSQUALITY \ 76 - (P80211DID_MKSECTION(3) | \ 77 - P80211DID_MKGROUP(4)) 78 - #define DIDMSG_LNXREQ_AUTOJOIN \ 79 - (P80211DID_MKSECTION(3) | \ 80 - P80211DID_MKGROUP(5)) 81 - #define DIDMSG_P2REQ_READPDA \ 82 - (P80211DID_MKSECTION(5) | \ 83 - P80211DID_MKGROUP(2)) 84 - #define DIDMSG_P2REQ_READPDA_PDA \ 85 - (P80211DID_MKSECTION(5) | \ 86 - P80211DID_MKGROUP(2) | \ 87 - P80211DID_MKITEM(1) | 0x00000000) 88 - #define DIDMSG_P2REQ_READPDA_RESULTCODE \ 89 - (P80211DID_MKSECTION(5) | \ 90 - P80211DID_MKGROUP(2) | \ 91 - P80211DID_MKITEM(2) | 0x00000000) 92 - #define DIDMSG_P2REQ_RAMDL_STATE \ 93 - (P80211DID_MKSECTION(5) | \ 94 - P80211DID_MKGROUP(11)) 95 - #define DIDMSG_P2REQ_RAMDL_STATE_ENABLE \ 96 - (P80211DID_MKSECTION(5) | \ 97 - P80211DID_MKGROUP(11) | \ 98 - P80211DID_MKITEM(1) | 0x00000000) 99 - #define DIDMSG_P2REQ_RAMDL_STATE_EXEADDR \ 100 - (P80211DID_MKSECTION(5) | \ 101 - P80211DID_MKGROUP(11) | \ 102 - P80211DID_MKITEM(2) | 0x00000000) 103 - #define DIDMSG_P2REQ_RAMDL_STATE_RESULTCODE \ 104 - (P80211DID_MKSECTION(5) | \ 105 - P80211DID_MKGROUP(11) | \ 106 - P80211DID_MKITEM(3) | 0x00000000) 107 - #define DIDMSG_P2REQ_RAMDL_WRITE \ 108 - (P80211DID_MKSECTION(5) | \ 109 - P80211DID_MKGROUP(12)) 110 - #define DIDMSG_P2REQ_RAMDL_WRITE_ADDR \ 111 - (P80211DID_MKSECTION(5) | \ 112 - P80211DID_MKGROUP(12) | \ 113 - P80211DID_MKITEM(1) | 0x00000000) 114 - #define DIDMSG_P2REQ_RAMDL_WRITE_LEN \ 115 - (P80211DID_MKSECTION(5) | \ 116 - P80211DID_MKGROUP(12) | \ 117 - P80211DID_MKITEM(2) | 0x00000000) 118 - #define DIDMSG_P2REQ_RAMDL_WRITE_DATA \ 119 - (P80211DID_MKSECTION(5) | \ 120 - P80211DID_MKGROUP(12) | \ 121 - P80211DID_MKITEM(3) | 0x00000000) 122 - #define DIDMSG_P2REQ_RAMDL_WRITE_RESULTCODE \ 123 - (P80211DID_MKSECTION(5) | \ 124 - P80211DID_MKGROUP(12) | \ 125 - P80211DID_MKITEM(4) | 0x00000000) 126 - #define DIDMSG_P2REQ_FLASHDL_STATE \ 127 - (P80211DID_MKSECTION(5) | \ 128 - P80211DID_MKGROUP(13)) 129 - #define DIDMSG_P2REQ_FLASHDL_WRITE \ 130 - (P80211DID_MKSECTION(5) | \ 131 - P80211DID_MKGROUP(14)) 132 - #define DIDMIB_CAT_DOT11SMT \ 133 - P80211DID_MKSECTION(1) 134 - #define DIDMIB_DOT11SMT_WEPDEFAULTKEYSTABLE \ 135 - (P80211DID_MKSECTION(1) | \ 136 - P80211DID_MKGROUP(4)) 137 - #define didmib_dot11smt_wepdefaultkeystable_key(_i) \ 138 - (DIDMIB_DOT11SMT_WEPDEFAULTKEYSTABLE | \ 139 - P80211DID_MKITEM(_i) | 0x0c000000) 140 - #define DIDMIB_DOT11SMT_PRIVACYTABLE \ 141 - (P80211DID_MKSECTION(1) | \ 142 - P80211DID_MKGROUP(6)) 143 - #define DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED \ 144 - (P80211DID_MKSECTION(1) | \ 145 - P80211DID_MKGROUP(6) | \ 146 - P80211DID_MKITEM(1) | 0x18000000) 147 - #define DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID \ 148 - (P80211DID_MKSECTION(1) | \ 149 - P80211DID_MKGROUP(6) | \ 150 - P80211DID_MKITEM(2) | 0x18000000) 151 - #define DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED \ 152 - (P80211DID_MKSECTION(1) | \ 153 - P80211DID_MKGROUP(6) | \ 154 - P80211DID_MKITEM(4) | 0x18000000) 155 - #define DIDMIB_DOT11MAC_OPERATIONTABLE \ 156 - (P80211DID_MKSECTION(2) | \ 157 - P80211DID_MKGROUP(1)) 158 - #define DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS \ 159 - (P80211DID_MKSECTION(2) | \ 160 - P80211DID_MKGROUP(1) | \ 161 - P80211DID_MKITEM(1) | 0x18000000) 162 - #define DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD \ 163 - (P80211DID_MKSECTION(2) | \ 164 - P80211DID_MKGROUP(1) | \ 165 - P80211DID_MKITEM(2) | 0x18000000) 166 - #define DIDMIB_DOT11MAC_OPERATIONTABLE_SHORTRETRYLIMIT \ 167 - (P80211DID_MKSECTION(2) | \ 168 - P80211DID_MKGROUP(1) | \ 169 - P80211DID_MKITEM(3) | 0x10000000) 170 - #define DIDMIB_DOT11MAC_OPERATIONTABLE_LONGRETRYLIMIT \ 171 - (P80211DID_MKSECTION(2) | \ 172 - P80211DID_MKGROUP(1) | \ 173 - P80211DID_MKITEM(4) | 0x10000000) 174 - #define DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD \ 175 - (P80211DID_MKSECTION(2) | \ 176 - P80211DID_MKGROUP(1) | \ 177 - P80211DID_MKITEM(5) | 0x18000000) 178 - #define DIDMIB_DOT11MAC_OPERATIONTABLE_MAXTRANSMITMSDULIFETIME \ 179 - (P80211DID_MKSECTION(2) | \ 180 - P80211DID_MKGROUP(1) | \ 181 - P80211DID_MKITEM(6) | 0x10000000) 182 - #define DIDMIB_CAT_DOT11PHY \ 183 - P80211DID_MKSECTION(3) 184 - #define DIDMIB_DOT11PHY_OPERATIONTABLE \ 185 - (P80211DID_MKSECTION(3) | \ 186 - P80211DID_MKGROUP(1)) 187 - #define DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL \ 188 - (P80211DID_MKSECTION(3) | \ 189 - P80211DID_MKGROUP(3) | \ 190 - P80211DID_MKITEM(10) | 0x18000000) 191 - #define DIDMIB_DOT11PHY_DSSSTABLE \ 192 - (P80211DID_MKSECTION(3) | \ 193 - P80211DID_MKGROUP(5)) 194 - #define DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL \ 195 - (P80211DID_MKSECTION(3) | \ 196 - P80211DID_MKGROUP(5) | \ 197 - P80211DID_MKITEM(1) | 0x10000000) 198 - #define DIDMIB_CAT_LNX \ 199 - P80211DID_MKSECTION(4) 200 - #define DIDMIB_LNX_CONFIGTABLE \ 201 - (P80211DID_MKSECTION(4) | \ 202 - P80211DID_MKGROUP(1)) 203 - #define DIDMIB_LNX_CONFIGTABLE_RSNAIE \ 204 - (P80211DID_MKSECTION(4) | \ 205 - P80211DID_MKGROUP(1) | \ 206 - P80211DID_MKITEM(1) | 0x18000000) 207 - #define DIDMIB_CAT_P2 \ 208 - P80211DID_MKSECTION(5) 209 - #define DIDMIB_P2_STATIC \ 210 - (P80211DID_MKSECTION(5) | \ 211 - P80211DID_MKGROUP(2)) 212 - #define DIDMIB_P2_STATIC_CNFPORTTYPE \ 213 - (P80211DID_MKSECTION(5) | \ 214 - P80211DID_MKGROUP(2) | \ 215 - P80211DID_MKITEM(1) | 0x18000000) 216 - #define DIDMIB_P2_NIC_PRISUPRANGE \ 217 - (P80211DID_MKSECTION(5) | \ 218 - P80211DID_MKGROUP(5) | \ 219 - P80211DID_MKITEM(6) | 0x10000000) 220 - #define DIDMIB_P2_MAC \ 221 - (P80211DID_MKSECTION(5) | \ 222 - P80211DID_MKGROUP(6)) 223 - #define DIDMIB_P2_MAC_CURRENTTXRATE \ 224 - (P80211DID_MKSECTION(5) | \ 225 - P80211DID_MKGROUP(6) | \ 226 - P80211DID_MKITEM(12) | 0x10000000) 227 - #endif
-236
drivers/staging/wlan-ng/p80211metastruct.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* -------------------------------------------------------------------- 3 - * 4 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 5 - * -------------------------------------------------------------------- 6 - * 7 - * linux-wlan 8 - * 9 - * -------------------------------------------------------------------- 10 - * 11 - * Inquiries regarding the linux-wlan Open Source project can be 12 - * made directly to: 13 - * 14 - * AbsoluteValue Systems Inc. 15 - * info@linux-wlan.com 16 - * http://www.linux-wlan.com 17 - * 18 - * -------------------------------------------------------------------- 19 - * 20 - * Portions of the development of this software were funded by 21 - * Intersil Corporation as part of PRISM(R) chipset product development. 22 - * 23 - * -------------------------------------------------------------------- 24 - */ 25 - 26 - #ifndef _P80211MKMETASTRUCT_H 27 - #define _P80211MKMETASTRUCT_H 28 - 29 - struct p80211msg_dot11req_mibget { 30 - u32 msgcode; 31 - u32 msglen; 32 - u8 devname[WLAN_DEVNAMELEN_MAX]; 33 - struct p80211item_unk392 mibattribute; 34 - struct p80211item_uint32 resultcode; 35 - } __packed; 36 - 37 - struct p80211msg_dot11req_mibset { 38 - u32 msgcode; 39 - u32 msglen; 40 - u8 devname[WLAN_DEVNAMELEN_MAX]; 41 - struct p80211item_unk392 mibattribute; 42 - struct p80211item_uint32 resultcode; 43 - } __packed; 44 - 45 - struct p80211msg_dot11req_scan { 46 - u32 msgcode; 47 - u32 msglen; 48 - u8 devname[WLAN_DEVNAMELEN_MAX]; 49 - struct p80211item_uint32 bsstype; 50 - struct p80211item_pstr6 bssid; 51 - u8 pad_0C[1]; 52 - struct p80211item_pstr32 ssid; 53 - u8 pad_1D[3]; 54 - struct p80211item_uint32 scantype; 55 - struct p80211item_uint32 probedelay; 56 - struct p80211item_pstr14 channellist; 57 - u8 pad_2C[1]; 58 - struct p80211item_uint32 minchanneltime; 59 - struct p80211item_uint32 maxchanneltime; 60 - struct p80211item_uint32 resultcode; 61 - struct p80211item_uint32 numbss; 62 - struct p80211item_uint32 append; 63 - } __packed; 64 - 65 - struct p80211msg_dot11req_scan_results { 66 - u32 msgcode; 67 - u32 msglen; 68 - u8 devname[WLAN_DEVNAMELEN_MAX]; 69 - struct p80211item_uint32 bssindex; 70 - struct p80211item_uint32 resultcode; 71 - struct p80211item_uint32 signal; 72 - struct p80211item_uint32 noise; 73 - struct p80211item_pstr6 bssid; 74 - u8 pad_3C[1]; 75 - struct p80211item_pstr32 ssid; 76 - u8 pad_4D[3]; 77 - struct p80211item_uint32 bsstype; 78 - struct p80211item_uint32 beaconperiod; 79 - struct p80211item_uint32 dtimperiod; 80 - struct p80211item_uint32 timestamp; 81 - struct p80211item_uint32 localtime; 82 - struct p80211item_uint32 fhdwelltime; 83 - struct p80211item_uint32 fhhopset; 84 - struct p80211item_uint32 fhhoppattern; 85 - struct p80211item_uint32 fhhopindex; 86 - struct p80211item_uint32 dschannel; 87 - struct p80211item_uint32 cfpcount; 88 - struct p80211item_uint32 cfpperiod; 89 - struct p80211item_uint32 cfpmaxduration; 90 - struct p80211item_uint32 cfpdurremaining; 91 - struct p80211item_uint32 ibssatimwindow; 92 - struct p80211item_uint32 cfpollable; 93 - struct p80211item_uint32 cfpollreq; 94 - struct p80211item_uint32 privacy; 95 - struct p80211item_uint32 capinfo; 96 - struct p80211item_uint32 basicrate[8]; 97 - struct p80211item_uint32 supprate[8]; 98 - } __packed; 99 - 100 - struct p80211msg_dot11req_start { 101 - u32 msgcode; 102 - u32 msglen; 103 - u8 devname[WLAN_DEVNAMELEN_MAX]; 104 - struct p80211item_pstr32 ssid; 105 - u8 pad_12D[3]; 106 - struct p80211item_uint32 bsstype; 107 - struct p80211item_uint32 beaconperiod; 108 - struct p80211item_uint32 dtimperiod; 109 - struct p80211item_uint32 cfpperiod; 110 - struct p80211item_uint32 cfpmaxduration; 111 - struct p80211item_uint32 fhdwelltime; 112 - struct p80211item_uint32 fhhopset; 113 - struct p80211item_uint32 fhhoppattern; 114 - struct p80211item_uint32 dschannel; 115 - struct p80211item_uint32 ibssatimwindow; 116 - struct p80211item_uint32 probedelay; 117 - struct p80211item_uint32 cfpollable; 118 - struct p80211item_uint32 cfpollreq; 119 - struct p80211item_uint32 basicrate1; 120 - struct p80211item_uint32 basicrate2; 121 - struct p80211item_uint32 basicrate3; 122 - struct p80211item_uint32 basicrate4; 123 - struct p80211item_uint32 basicrate5; 124 - struct p80211item_uint32 basicrate6; 125 - struct p80211item_uint32 basicrate7; 126 - struct p80211item_uint32 basicrate8; 127 - struct p80211item_uint32 operationalrate1; 128 - struct p80211item_uint32 operationalrate2; 129 - struct p80211item_uint32 operationalrate3; 130 - struct p80211item_uint32 operationalrate4; 131 - struct p80211item_uint32 operationalrate5; 132 - struct p80211item_uint32 operationalrate6; 133 - struct p80211item_uint32 operationalrate7; 134 - struct p80211item_uint32 operationalrate8; 135 - struct p80211item_uint32 resultcode; 136 - } __packed; 137 - 138 - struct p80211msg_lnxreq_ifstate { 139 - u32 msgcode; 140 - u32 msglen; 141 - u8 devname[WLAN_DEVNAMELEN_MAX]; 142 - struct p80211item_uint32 ifstate; 143 - struct p80211item_uint32 resultcode; 144 - } __packed; 145 - 146 - struct p80211msg_lnxreq_wlansniff { 147 - u32 msgcode; 148 - u32 msglen; 149 - u8 devname[WLAN_DEVNAMELEN_MAX]; 150 - struct p80211item_uint32 enable; 151 - struct p80211item_uint32 channel; 152 - struct p80211item_uint32 prismheader; 153 - struct p80211item_uint32 wlanheader; 154 - struct p80211item_uint32 keepwepflags; 155 - struct p80211item_uint32 stripfcs; 156 - struct p80211item_uint32 packet_trunc; 157 - struct p80211item_uint32 resultcode; 158 - } __packed; 159 - 160 - struct p80211msg_lnxreq_hostwep { 161 - u32 msgcode; 162 - u32 msglen; 163 - u8 devname[WLAN_DEVNAMELEN_MAX]; 164 - struct p80211item_uint32 resultcode; 165 - struct p80211item_uint32 decrypt; 166 - struct p80211item_uint32 encrypt; 167 - } __packed; 168 - 169 - struct p80211msg_lnxreq_commsquality { 170 - u32 msgcode; 171 - u32 msglen; 172 - u8 devname[WLAN_DEVNAMELEN_MAX]; 173 - struct p80211item_uint32 resultcode; 174 - struct p80211item_uint32 dbm; 175 - struct p80211item_uint32 link; 176 - struct p80211item_uint32 level; 177 - struct p80211item_uint32 noise; 178 - struct p80211item_uint32 txrate; 179 - } __packed; 180 - 181 - struct p80211msg_lnxreq_autojoin { 182 - u32 msgcode; 183 - u32 msglen; 184 - u8 devname[WLAN_DEVNAMELEN_MAX]; 185 - struct p80211item_pstr32 ssid; 186 - u8 pad_19D[3]; 187 - struct p80211item_uint32 authtype; 188 - struct p80211item_uint32 resultcode; 189 - } __packed; 190 - 191 - struct p80211msg_p2req_readpda { 192 - u32 msgcode; 193 - u32 msglen; 194 - u8 devname[WLAN_DEVNAMELEN_MAX]; 195 - struct p80211item_unk1024 pda; 196 - struct p80211item_uint32 resultcode; 197 - } __packed; 198 - 199 - struct p80211msg_p2req_ramdl_state { 200 - u32 msgcode; 201 - u32 msglen; 202 - u8 devname[WLAN_DEVNAMELEN_MAX]; 203 - struct p80211item_uint32 enable; 204 - struct p80211item_uint32 exeaddr; 205 - struct p80211item_uint32 resultcode; 206 - } __packed; 207 - 208 - struct p80211msg_p2req_ramdl_write { 209 - u32 msgcode; 210 - u32 msglen; 211 - u8 devname[WLAN_DEVNAMELEN_MAX]; 212 - struct p80211item_uint32 addr; 213 - struct p80211item_uint32 len; 214 - struct p80211item_unk4096 data; 215 - struct p80211item_uint32 resultcode; 216 - } __packed; 217 - 218 - struct p80211msg_p2req_flashdl_state { 219 - u32 msgcode; 220 - u32 msglen; 221 - u8 devname[WLAN_DEVNAMELEN_MAX]; 222 - struct p80211item_uint32 enable; 223 - struct p80211item_uint32 resultcode; 224 - } __packed; 225 - 226 - struct p80211msg_p2req_flashdl_write { 227 - u32 msgcode; 228 - u32 msglen; 229 - u8 devname[WLAN_DEVNAMELEN_MAX]; 230 - struct p80211item_uint32 addr; 231 - struct p80211item_uint32 len; 232 - struct p80211item_unk4096 data; 233 - struct p80211item_uint32 resultcode; 234 - } __packed; 235 - 236 - #endif
-199
drivers/staging/wlan-ng/p80211mgmt.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Macros, types, and functions to handle 802.11 mgmt frames 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file declares the constants and types used in the interface 28 - * between a wlan driver and the user mode utilities. 29 - * 30 - * Notes: 31 - * - Constant values are always in HOST byte order. To assign 32 - * values to multi-byte fields they _must_ be converted to 33 - * ieee byte order. To retrieve multi-byte values from incoming 34 - * frames, they must be converted to host order. 35 - * 36 - * - The len member of the frame structure does NOT!!! include 37 - * the MAC CRC. Therefore, the len field on rx'd frames should 38 - * have 4 subtracted from it. 39 - * 40 - * All functions declared here are implemented in p80211.c 41 - * 42 - * The types, macros, and functions defined here are primarily 43 - * used for encoding and decoding management frames. They are 44 - * designed to follow these patterns of use: 45 - * 46 - * DECODE: 47 - * 1) a frame of length len is received into buffer b 48 - * 2) using the hdr structure and macros, we determine the type 49 - * 3) an appropriate mgmt frame structure, mf, is allocated and zeroed 50 - * 4) mf.hdr = b 51 - * mf.buf = b 52 - * mf.len = len 53 - * 5) call mgmt_decode( mf ) 54 - * 6) the frame field pointers in mf are now set. Note that any 55 - * multi-byte frame field values accessed using the frame field 56 - * pointers are in ieee byte order and will have to be converted 57 - * to host order. 58 - * 59 - * ENCODE: 60 - * 1) Library client allocates buffer space for maximum length 61 - * frame of the desired type 62 - * 2) Library client allocates a mgmt frame structure, called mf, 63 - * of the desired type 64 - * 3) Set the following: 65 - * mf.type = <desired type> 66 - * mf.buf = <allocated buffer address> 67 - * 4) call mgmt_encode( mf ) 68 - * 5) all of the fixed field pointers and fixed length information element 69 - * pointers in mf are now set to their respective locations in the 70 - * allocated space (fortunately, all variable length information elements 71 - * fall at the end of their respective frames). 72 - * 5a) The length field is set to include the last of the fixed and fixed 73 - * length fields. It may have to be updated for optional or variable 74 - * length information elements. 75 - * 6) Optional and variable length information elements are special cases 76 - * and must be handled individually by the client code. 77 - * -------------------------------------------------------------------- 78 - */ 79 - 80 - #ifndef _P80211MGMT_H 81 - #define _P80211MGMT_H 82 - 83 - #ifndef _P80211HDR_H 84 - #include "p80211hdr.h" 85 - #endif 86 - 87 - /*-- Information Element IDs --------------------*/ 88 - #define WLAN_EID_SSID 0 89 - #define WLAN_EID_SUPP_RATES 1 90 - #define WLAN_EID_FH_PARMS 2 91 - #define WLAN_EID_DS_PARMS 3 92 - #define WLAN_EID_CF_PARMS 4 93 - #define WLAN_EID_TIM 5 94 - #define WLAN_EID_IBSS_PARMS 6 95 - /*-- values 7-15 reserved --*/ 96 - #define WLAN_EID_CHALLENGE 16 97 - /*-- values 17-31 reserved for challenge text extension --*/ 98 - /*-- values 32-255 reserved --*/ 99 - 100 - /*-- Reason Codes -------------------------------*/ 101 - #define WLAN_MGMT_REASON_RSVD 0 102 - #define WLAN_MGMT_REASON_UNSPEC 1 103 - #define WLAN_MGMT_REASON_PRIOR_AUTH_INVALID 2 104 - #define WLAN_MGMT_REASON_DEAUTH_LEAVING 3 105 - #define WLAN_MGMT_REASON_DISASSOC_INACTIVE 4 106 - #define WLAN_MGMT_REASON_DISASSOC_AP_BUSY 5 107 - #define WLAN_MGMT_REASON_CLASS2_NONAUTH 6 108 - #define WLAN_MGMT_REASON_CLASS3_NONASSOC 7 109 - #define WLAN_MGMT_REASON_DISASSOC_STA_HASLEFT 8 110 - #define WLAN_MGMT_REASON_CANT_ASSOC_NONAUTH 9 111 - 112 - /*-- Status Codes -------------------------------*/ 113 - #define WLAN_MGMT_STATUS_SUCCESS 0 114 - #define WLAN_MGMT_STATUS_UNSPEC_FAILURE 1 115 - #define WLAN_MGMT_STATUS_CAPS_UNSUPPORTED 10 116 - #define WLAN_MGMT_STATUS_REASSOC_NO_ASSOC 11 117 - #define WLAN_MGMT_STATUS_ASSOC_DENIED_UNSPEC 12 118 - #define WLAN_MGMT_STATUS_UNSUPPORTED_AUTHALG 13 119 - #define WLAN_MGMT_STATUS_RX_AUTH_NOSEQ 14 120 - #define WLAN_MGMT_STATUS_CHALLENGE_FAIL 15 121 - #define WLAN_MGMT_STATUS_AUTH_TIMEOUT 16 122 - #define WLAN_MGMT_STATUS_ASSOC_DENIED_BUSY 17 123 - #define WLAN_MGMT_STATUS_ASSOC_DENIED_RATES 18 124 - /* p80211b additions */ 125 - #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOSHORT 19 126 - #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOPBCC 20 127 - #define WLAN_MGMT_STATUS_ASSOC_DENIED_NOAGILITY 21 128 - 129 - /*-- Auth Algorithm Field ---------------------------*/ 130 - #define WLAN_AUTH_ALG_OPENSYSTEM 0 131 - #define WLAN_AUTH_ALG_SHAREDKEY 1 132 - 133 - /*-- Management Frame Field Offsets -------------*/ 134 - /* Note: Not all fields are listed because of variable lengths, */ 135 - /* see the code in p80211.c to see how we search for fields */ 136 - /* Note: These offsets are from the start of the frame data */ 137 - 138 - #define WLAN_BEACON_OFF_TS 0 139 - #define WLAN_BEACON_OFF_BCN_int 8 140 - #define WLAN_BEACON_OFF_CAPINFO 10 141 - #define WLAN_BEACON_OFF_SSID 12 142 - 143 - #define WLAN_DISASSOC_OFF_REASON 0 144 - 145 - #define WLAN_ASSOCREQ_OFF_CAP_INFO 0 146 - #define WLAN_ASSOCREQ_OFF_LISTEN_int 2 147 - #define WLAN_ASSOCREQ_OFF_SSID 4 148 - 149 - #define WLAN_ASSOCRESP_OFF_CAP_INFO 0 150 - #define WLAN_ASSOCRESP_OFF_STATUS 2 151 - #define WLAN_ASSOCRESP_OFF_AID 4 152 - #define WLAN_ASSOCRESP_OFF_SUPP_RATES 6 153 - 154 - #define WLAN_REASSOCREQ_OFF_CAP_INFO 0 155 - #define WLAN_REASSOCREQ_OFF_LISTEN_int 2 156 - #define WLAN_REASSOCREQ_OFF_CURR_AP 4 157 - #define WLAN_REASSOCREQ_OFF_SSID 10 158 - 159 - #define WLAN_REASSOCRESP_OFF_CAP_INFO 0 160 - #define WLAN_REASSOCRESP_OFF_STATUS 2 161 - #define WLAN_REASSOCRESP_OFF_AID 4 162 - #define WLAN_REASSOCRESP_OFF_SUPP_RATES 6 163 - 164 - #define WLAN_PROBEREQ_OFF_SSID 0 165 - 166 - #define WLAN_PROBERESP_OFF_TS 0 167 - #define WLAN_PROBERESP_OFF_BCN_int 8 168 - #define WLAN_PROBERESP_OFF_CAP_INFO 10 169 - #define WLAN_PROBERESP_OFF_SSID 12 170 - 171 - #define WLAN_AUTHEN_OFF_AUTH_ALG 0 172 - #define WLAN_AUTHEN_OFF_AUTH_SEQ 2 173 - #define WLAN_AUTHEN_OFF_STATUS 4 174 - #define WLAN_AUTHEN_OFF_CHALLENGE 6 175 - 176 - #define WLAN_DEAUTHEN_OFF_REASON 0 177 - 178 - /*-- Capability Field ---------------------------*/ 179 - #define WLAN_GET_MGMT_CAP_INFO_ESS(n) ((n) & BIT(0)) 180 - #define WLAN_GET_MGMT_CAP_INFO_IBSS(n) (((n) & BIT(1)) >> 1) 181 - #define WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(n) (((n) & BIT(2)) >> 2) 182 - #define WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(n) (((n) & BIT(3)) >> 3) 183 - #define WLAN_GET_MGMT_CAP_INFO_PRIVACY(n) (((n) & BIT(4)) >> 4) 184 - /* p80211b additions */ 185 - #define WLAN_GET_MGMT_CAP_INFO_SHORT(n) (((n) & BIT(5)) >> 5) 186 - #define WLAN_GET_MGMT_CAP_INFO_PBCC(n) (((n) & BIT(6)) >> 6) 187 - #define WLAN_GET_MGMT_CAP_INFO_AGILITY(n) (((n) & BIT(7)) >> 7) 188 - 189 - #define WLAN_SET_MGMT_CAP_INFO_ESS(n) (n) 190 - #define WLAN_SET_MGMT_CAP_INFO_IBSS(n) ((n) << 1) 191 - #define WLAN_SET_MGMT_CAP_INFO_CFPOLLABLE(n) ((n) << 2) 192 - #define WLAN_SET_MGMT_CAP_INFO_CFPOLLREQ(n) ((n) << 3) 193 - #define WLAN_SET_MGMT_CAP_INFO_PRIVACY(n) ((n) << 4) 194 - /* p80211b additions */ 195 - #define WLAN_SET_MGMT_CAP_INFO_SHORT(n) ((n) << 5) 196 - #define WLAN_SET_MGMT_CAP_INFO_PBCC(n) ((n) << 6) 197 - #define WLAN_SET_MGMT_CAP_INFO_AGILITY(n) ((n) << 7) 198 - 199 - #endif /* _P80211MGMT_H */
-39
drivers/staging/wlan-ng/p80211msg.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Macros, constants, types, and funcs for req and ind messages 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - */ 27 - 28 - #ifndef _P80211MSG_H 29 - #define _P80211MSG_H 30 - 31 - #define WLAN_DEVNAMELEN_MAX 16 32 - 33 - struct p80211msg { 34 - u32 msgcode; 35 - u32 msglen; 36 - u8 devname[WLAN_DEVNAMELEN_MAX]; 37 - } __packed; 38 - 39 - #endif /* _P80211MSG_H */
-988
drivers/staging/wlan-ng/p80211netdev.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Linux Kernel net device interface 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * The functions required for a Linux network device are defined here. 28 - * 29 - * -------------------------------------------------------------------- 30 - */ 31 - 32 - #include <linux/module.h> 33 - #include <linux/kernel.h> 34 - #include <linux/sched.h> 35 - #include <linux/types.h> 36 - #include <linux/skbuff.h> 37 - #include <linux/slab.h> 38 - #include <linux/proc_fs.h> 39 - #include <linux/interrupt.h> 40 - #include <linux/netdevice.h> 41 - #include <linux/kmod.h> 42 - #include <linux/if_arp.h> 43 - #include <linux/wireless.h> 44 - #include <linux/sockios.h> 45 - #include <linux/etherdevice.h> 46 - #include <linux/if_ether.h> 47 - #include <linux/byteorder/generic.h> 48 - #include <linux/bitops.h> 49 - #include <linux/uaccess.h> 50 - #include <asm/byteorder.h> 51 - 52 - #ifdef SIOCETHTOOL 53 - #include <linux/ethtool.h> 54 - #endif 55 - 56 - #include <net/iw_handler.h> 57 - #include <net/net_namespace.h> 58 - #include <net/cfg80211.h> 59 - 60 - #include "p80211types.h" 61 - #include "p80211hdr.h" 62 - #include "p80211conv.h" 63 - #include "p80211mgmt.h" 64 - #include "p80211msg.h" 65 - #include "p80211netdev.h" 66 - #include "p80211ioctl.h" 67 - #include "p80211req.h" 68 - #include "p80211metastruct.h" 69 - #include "p80211metadef.h" 70 - 71 - #include "cfg80211.c" 72 - 73 - /* netdevice method functions */ 74 - static int p80211knetdev_init(struct net_device *netdev); 75 - static int p80211knetdev_open(struct net_device *netdev); 76 - static int p80211knetdev_stop(struct net_device *netdev); 77 - static netdev_tx_t p80211knetdev_hard_start_xmit(struct sk_buff *skb, 78 - struct net_device *netdev); 79 - static void p80211knetdev_set_multicast_list(struct net_device *dev); 80 - static int p80211knetdev_siocdevprivate(struct net_device *dev, struct ifreq *ifr, 81 - void __user *data, int cmd); 82 - static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr); 83 - static void p80211knetdev_tx_timeout(struct net_device *netdev, unsigned int txqueue); 84 - static int p80211_rx_typedrop(struct wlandevice *wlandev, u16 fc); 85 - 86 - int wlan_watchdog = 5000; 87 - module_param(wlan_watchdog, int, 0644); 88 - MODULE_PARM_DESC(wlan_watchdog, "transmit timeout in milliseconds"); 89 - 90 - int wlan_wext_write = 1; 91 - module_param(wlan_wext_write, int, 0644); 92 - MODULE_PARM_DESC(wlan_wext_write, "enable write wireless extensions"); 93 - 94 - /*---------------------------------------------------------------- 95 - * p80211knetdev_init 96 - * 97 - * Init method for a Linux netdevice. Called in response to 98 - * register_netdev. 99 - * 100 - * Arguments: 101 - * none 102 - * 103 - * Returns: 104 - * nothing 105 - *---------------------------------------------------------------- 106 - */ 107 - static int p80211knetdev_init(struct net_device *netdev) 108 - { 109 - /* Called in response to register_netdev */ 110 - /* This is usually the probe function, but the probe has */ 111 - /* already been done by the MSD and the create_kdev */ 112 - /* function. All we do here is return success */ 113 - return 0; 114 - } 115 - 116 - /*---------------------------------------------------------------- 117 - * p80211knetdev_open 118 - * 119 - * Linux netdevice open method. Following a successful call here, 120 - * the device is supposed to be ready for tx and rx. In our 121 - * situation that may not be entirely true due to the state of the 122 - * MAC below. 123 - * 124 - * Arguments: 125 - * netdev Linux network device structure 126 - * 127 - * Returns: 128 - * zero on success, non-zero otherwise 129 - *---------------------------------------------------------------- 130 - */ 131 - static int p80211knetdev_open(struct net_device *netdev) 132 - { 133 - int result = 0; /* success */ 134 - struct wlandevice *wlandev = netdev->ml_priv; 135 - 136 - /* Check to make sure the MSD is running */ 137 - if (wlandev->msdstate != WLAN_MSD_RUNNING) 138 - return -ENODEV; 139 - 140 - /* Tell the MSD to open */ 141 - if (wlandev->open) { 142 - result = wlandev->open(wlandev); 143 - if (result == 0) { 144 - netif_start_queue(wlandev->netdev); 145 - wlandev->state = WLAN_DEVICE_OPEN; 146 - } 147 - } else { 148 - result = -EAGAIN; 149 - } 150 - 151 - return result; 152 - } 153 - 154 - /*---------------------------------------------------------------- 155 - * p80211knetdev_stop 156 - * 157 - * Linux netdevice stop (close) method. Following this call, 158 - * no frames should go up or down through this interface. 159 - * 160 - * Arguments: 161 - * netdev Linux network device structure 162 - * 163 - * Returns: 164 - * zero on success, non-zero otherwise 165 - *---------------------------------------------------------------- 166 - */ 167 - static int p80211knetdev_stop(struct net_device *netdev) 168 - { 169 - int result = 0; 170 - struct wlandevice *wlandev = netdev->ml_priv; 171 - 172 - if (wlandev->close) 173 - result = wlandev->close(wlandev); 174 - 175 - netif_stop_queue(wlandev->netdev); 176 - wlandev->state = WLAN_DEVICE_CLOSED; 177 - 178 - return result; 179 - } 180 - 181 - /*---------------------------------------------------------------- 182 - * p80211netdev_rx 183 - * 184 - * Frame receive function called by the mac specific driver. 185 - * 186 - * Arguments: 187 - * wlandev WLAN network device structure 188 - * skb skbuff containing a full 802.11 frame. 189 - * Returns: 190 - * nothing 191 - * Side effects: 192 - * 193 - *---------------------------------------------------------------- 194 - */ 195 - void p80211netdev_rx(struct wlandevice *wlandev, struct sk_buff *skb) 196 - { 197 - /* Enqueue for post-irq processing */ 198 - skb_queue_tail(&wlandev->nsd_rxq, skb); 199 - tasklet_schedule(&wlandev->rx_bh); 200 - } 201 - 202 - #define CONV_TO_ETHER_SKIPPED 0x01 203 - #define CONV_TO_ETHER_FAILED 0x02 204 - 205 - /** 206 - * p80211_convert_to_ether - conversion from 802.11 frame to ethernet frame 207 - * @wlandev: pointer to WLAN device 208 - * @skb: pointer to socket buffer 209 - * 210 - * Returns: 0 if conversion succeeded 211 - * CONV_TO_ETHER_FAILED if conversion failed 212 - * CONV_TO_ETHER_SKIPPED if frame is ignored 213 - */ 214 - static int p80211_convert_to_ether(struct wlandevice *wlandev, 215 - struct sk_buff *skb) 216 - { 217 - struct p80211_hdr *hdr; 218 - 219 - hdr = (struct p80211_hdr *)skb->data; 220 - if (p80211_rx_typedrop(wlandev, le16_to_cpu(hdr->frame_control))) 221 - return CONV_TO_ETHER_SKIPPED; 222 - 223 - /* perform mcast filtering: allow my local address through but reject 224 - * anything else that isn't multicast 225 - */ 226 - if (wlandev->netdev->flags & IFF_ALLMULTI) { 227 - if (!ether_addr_equal_unaligned(wlandev->netdev->dev_addr, 228 - hdr->address1)) { 229 - if (!is_multicast_ether_addr(hdr->address1)) 230 - return CONV_TO_ETHER_SKIPPED; 231 - } 232 - } 233 - 234 - if (skb_p80211_to_ether(wlandev, wlandev->ethconv, skb) == 0) { 235 - wlandev->netdev->stats.rx_packets++; 236 - wlandev->netdev->stats.rx_bytes += skb->len; 237 - netif_rx(skb); 238 - return 0; 239 - } 240 - 241 - netdev_dbg(wlandev->netdev, "%s failed.\n", __func__); 242 - return CONV_TO_ETHER_FAILED; 243 - } 244 - 245 - /** 246 - * p80211netdev_rx_bh - deferred processing of all received frames 247 - * 248 - * @t: pointer to the tasklet associated with this handler 249 - */ 250 - static void p80211netdev_rx_bh(struct tasklet_struct *t) 251 - { 252 - struct wlandevice *wlandev = from_tasklet(wlandev, t, rx_bh); 253 - struct sk_buff *skb = NULL; 254 - struct net_device *dev = wlandev->netdev; 255 - 256 - /* Let's empty our queue */ 257 - while ((skb = skb_dequeue(&wlandev->nsd_rxq))) { 258 - if (wlandev->state == WLAN_DEVICE_OPEN) { 259 - if (dev->type != ARPHRD_ETHER) { 260 - /* RAW frame; we shouldn't convert it */ 261 - /* XXX Append the Prism Header here instead. */ 262 - 263 - /* set up various data fields */ 264 - skb->dev = dev; 265 - skb_reset_mac_header(skb); 266 - skb->ip_summed = CHECKSUM_NONE; 267 - skb->pkt_type = PACKET_OTHERHOST; 268 - skb->protocol = htons(ETH_P_80211_RAW); 269 - 270 - dev->stats.rx_packets++; 271 - dev->stats.rx_bytes += skb->len; 272 - netif_rx(skb); 273 - continue; 274 - } else { 275 - if (!p80211_convert_to_ether(wlandev, skb)) 276 - continue; 277 - } 278 - } 279 - dev_kfree_skb(skb); 280 - } 281 - } 282 - 283 - /*---------------------------------------------------------------- 284 - * p80211knetdev_hard_start_xmit 285 - * 286 - * Linux netdevice method for transmitting a frame. 287 - * 288 - * Arguments: 289 - * skb Linux sk_buff containing the frame. 290 - * netdev Linux netdevice. 291 - * 292 - * Side effects: 293 - * If the lower layers report that buffers are full. netdev->tbusy 294 - * will be set to prevent higher layers from sending more traffic. 295 - * 296 - * Note: If this function returns non-zero, higher layers retain 297 - * ownership of the skb. 298 - * 299 - * Returns: 300 - * zero on success, non-zero on failure. 301 - *---------------------------------------------------------------- 302 - */ 303 - static netdev_tx_t p80211knetdev_hard_start_xmit(struct sk_buff *skb, 304 - struct net_device *netdev) 305 - { 306 - int result = 0; 307 - int txresult; 308 - struct wlandevice *wlandev = netdev->ml_priv; 309 - struct p80211_hdr p80211_hdr; 310 - struct p80211_metawep p80211_wep; 311 - 312 - p80211_wep.data = NULL; 313 - 314 - if (!skb) 315 - return NETDEV_TX_OK; 316 - 317 - if (wlandev->state != WLAN_DEVICE_OPEN) { 318 - result = 1; 319 - goto failed; 320 - } 321 - 322 - memset(&p80211_hdr, 0, sizeof(p80211_hdr)); 323 - memset(&p80211_wep, 0, sizeof(p80211_wep)); 324 - 325 - if (netif_queue_stopped(netdev)) { 326 - netdev_dbg(netdev, "called when queue stopped.\n"); 327 - result = 1; 328 - goto failed; 329 - } 330 - 331 - netif_stop_queue(netdev); 332 - 333 - /* Check to see that a valid mode is set */ 334 - switch (wlandev->macmode) { 335 - case WLAN_MACMODE_IBSS_STA: 336 - case WLAN_MACMODE_ESS_STA: 337 - case WLAN_MACMODE_ESS_AP: 338 - break; 339 - default: 340 - /* Mode isn't set yet, just drop the frame 341 - * and return success . 342 - * TODO: we need a saner way to handle this 343 - */ 344 - if (be16_to_cpu(skb->protocol) != ETH_P_80211_RAW) { 345 - netif_start_queue(wlandev->netdev); 346 - netdev_notice(netdev, "Tx attempt prior to association, frame dropped.\n"); 347 - netdev->stats.tx_dropped++; 348 - result = 0; 349 - goto failed; 350 - } 351 - break; 352 - } 353 - 354 - /* Check for raw transmits */ 355 - if (be16_to_cpu(skb->protocol) == ETH_P_80211_RAW) { 356 - if (!capable(CAP_NET_ADMIN)) { 357 - result = 1; 358 - goto failed; 359 - } 360 - /* move the header over */ 361 - memcpy(&p80211_hdr, skb->data, sizeof(p80211_hdr)); 362 - skb_pull(skb, sizeof(p80211_hdr)); 363 - } else { 364 - if (skb_ether_to_p80211 365 - (wlandev, wlandev->ethconv, skb, &p80211_hdr, 366 - &p80211_wep) != 0) { 367 - /* convert failed */ 368 - netdev_dbg(netdev, "ether_to_80211(%d) failed.\n", 369 - wlandev->ethconv); 370 - result = 1; 371 - goto failed; 372 - } 373 - } 374 - if (!wlandev->txframe) { 375 - result = 1; 376 - goto failed; 377 - } 378 - 379 - netif_trans_update(netdev); 380 - 381 - netdev->stats.tx_packets++; 382 - /* count only the packet payload */ 383 - netdev->stats.tx_bytes += skb->len; 384 - 385 - txresult = wlandev->txframe(wlandev, skb, &p80211_hdr, &p80211_wep); 386 - 387 - if (txresult == 0) { 388 - /* success and more buf */ 389 - /* avail, re: hw_txdata */ 390 - netif_wake_queue(wlandev->netdev); 391 - result = NETDEV_TX_OK; 392 - } else if (txresult == 1) { 393 - /* success, no more avail */ 394 - netdev_dbg(netdev, "txframe success, no more bufs\n"); 395 - /* netdev->tbusy = 1; don't set here, irqhdlr */ 396 - /* may have already cleared it */ 397 - result = NETDEV_TX_OK; 398 - } else if (txresult == 2) { 399 - /* alloc failure, drop frame */ 400 - netdev_dbg(netdev, "txframe returned alloc_fail\n"); 401 - result = NETDEV_TX_BUSY; 402 - } else { 403 - /* buffer full or queue busy, drop frame. */ 404 - netdev_dbg(netdev, "txframe returned full or busy\n"); 405 - result = NETDEV_TX_BUSY; 406 - } 407 - 408 - failed: 409 - /* Free up the WEP buffer if it's not the same as the skb */ 410 - if ((p80211_wep.data) && (p80211_wep.data != skb->data)) 411 - kfree_sensitive(p80211_wep.data); 412 - 413 - /* we always free the skb here, never in a lower level. */ 414 - if (!result) 415 - dev_kfree_skb(skb); 416 - 417 - return result; 418 - } 419 - 420 - /*---------------------------------------------------------------- 421 - * p80211knetdev_set_multicast_list 422 - * 423 - * Called from higher layers whenever there's a need to set/clear 424 - * promiscuous mode or rewrite the multicast list. 425 - * 426 - * Arguments: 427 - * none 428 - * 429 - * Returns: 430 - * nothing 431 - *---------------------------------------------------------------- 432 - */ 433 - static void p80211knetdev_set_multicast_list(struct net_device *dev) 434 - { 435 - struct wlandevice *wlandev = dev->ml_priv; 436 - 437 - /* TODO: real multicast support as well */ 438 - 439 - if (wlandev->set_multicast_list) 440 - wlandev->set_multicast_list(wlandev, dev); 441 - } 442 - 443 - /*---------------------------------------------------------------- 444 - * p80211knetdev_siocdevprivate 445 - * 446 - * Handle an ioctl call on one of our devices. Everything Linux 447 - * ioctl specific is done here. Then we pass the contents of the 448 - * ifr->data to the request message handler. 449 - * 450 - * Arguments: 451 - * dev Linux kernel netdevice 452 - * ifr Our private ioctl request structure, typed for the 453 - * generic struct ifreq so we can use ptr to func 454 - * w/o cast. 455 - * 456 - * Returns: 457 - * zero on success, a negative errno on failure. Possible values: 458 - * -ENETDOWN Device isn't up. 459 - * -EBUSY cmd already in progress 460 - * -ETIME p80211 cmd timed out (MSD may have its own timers) 461 - * -EFAULT memory fault copying msg from user buffer 462 - * -ENOMEM unable to allocate kernel msg buffer 463 - * -EINVAL bad magic, it the cmd really for us? 464 - * -EintR sleeping on cmd, awakened by signal, cmd cancelled. 465 - * 466 - * Call Context: 467 - * Process thread (ioctl caller). TODO: SMP support may require 468 - * locks. 469 - *---------------------------------------------------------------- 470 - */ 471 - static int p80211knetdev_siocdevprivate(struct net_device *dev, 472 - struct ifreq *ifr, 473 - void __user *data, int cmd) 474 - { 475 - int result = 0; 476 - struct p80211ioctl_req *req = (struct p80211ioctl_req *)ifr; 477 - struct wlandevice *wlandev = dev->ml_priv; 478 - u8 *msgbuf; 479 - 480 - netdev_dbg(dev, "rx'd ioctl, cmd=%d, len=%d\n", cmd, req->len); 481 - 482 - if (in_compat_syscall()) 483 - return -EOPNOTSUPP; 484 - 485 - /* Test the magic, assume ifr is good if it's there */ 486 - if (req->magic != P80211_IOCTL_MAGIC) { 487 - result = -EINVAL; 488 - goto bail; 489 - } 490 - 491 - if (cmd == P80211_IFTEST) { 492 - result = 0; 493 - goto bail; 494 - } else if (cmd != P80211_IFREQ) { 495 - result = -EINVAL; 496 - goto bail; 497 - } 498 - 499 - msgbuf = memdup_user(data, req->len); 500 - if (IS_ERR(msgbuf)) { 501 - result = PTR_ERR(msgbuf); 502 - goto bail; 503 - } 504 - 505 - result = p80211req_dorequest(wlandev, msgbuf); 506 - 507 - if (result == 0) { 508 - if (copy_to_user(data, msgbuf, req->len)) 509 - result = -EFAULT; 510 - } 511 - kfree(msgbuf); 512 - 513 - bail: 514 - /* If allocate,copyfrom or copyto fails, return errno */ 515 - return result; 516 - } 517 - 518 - /*---------------------------------------------------------------- 519 - * p80211knetdev_set_mac_address 520 - * 521 - * Handles the ioctl for changing the MACAddress of a netdevice 522 - * 523 - * references: linux/netdevice.h and drivers/net/net_init.c 524 - * 525 - * NOTE: [MSM] We only prevent address changes when the netdev is 526 - * up. We don't control anything based on dot11 state. If the 527 - * address is changed on a STA that's currently associated, you 528 - * will probably lose the ability to send and receive data frames. 529 - * Just be aware. Therefore, this should usually only be done 530 - * prior to scan/join/auth/assoc. 531 - * 532 - * Arguments: 533 - * dev netdevice struct 534 - * addr the new MACAddress (a struct) 535 - * 536 - * Returns: 537 - * zero on success, a negative errno on failure. Possible values: 538 - * -EBUSY device is bussy (cmd not possible) 539 - * -and errors returned by: p80211req_dorequest(..) 540 - * 541 - * by: Collin R. Mulliner <collin@mulliner.org> 542 - *---------------------------------------------------------------- 543 - */ 544 - static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr) 545 - { 546 - struct sockaddr *new_addr = addr; 547 - struct p80211msg_dot11req_mibset dot11req; 548 - struct p80211item_unk392 *mibattr; 549 - struct p80211item_pstr6 *macaddr; 550 - struct p80211item_uint32 *resultcode; 551 - int result; 552 - 553 - /* If we're running, we don't allow MAC address changes */ 554 - if (netif_running(dev)) 555 - return -EBUSY; 556 - 557 - /* Set up some convenience pointers. */ 558 - mibattr = &dot11req.mibattribute; 559 - macaddr = (struct p80211item_pstr6 *)&mibattr->data; 560 - resultcode = &dot11req.resultcode; 561 - 562 - /* Set up a dot11req_mibset */ 563 - memset(&dot11req, 0, sizeof(dot11req)); 564 - dot11req.msgcode = DIDMSG_DOT11REQ_MIBSET; 565 - dot11req.msglen = sizeof(dot11req); 566 - memcpy(dot11req.devname, 567 - ((struct wlandevice *)dev->ml_priv)->name, 568 - WLAN_DEVNAMELEN_MAX - 1); 569 - 570 - /* Set up the mibattribute argument */ 571 - mibattr->did = DIDMSG_DOT11REQ_MIBSET_MIBATTRIBUTE; 572 - mibattr->status = P80211ENUM_msgitem_status_data_ok; 573 - mibattr->len = sizeof(mibattr->data); 574 - 575 - macaddr->did = DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS; 576 - macaddr->status = P80211ENUM_msgitem_status_data_ok; 577 - macaddr->len = sizeof(macaddr->data); 578 - macaddr->data.len = ETH_ALEN; 579 - memcpy(&macaddr->data.data, new_addr->sa_data, ETH_ALEN); 580 - 581 - /* Set up the resultcode argument */ 582 - resultcode->did = DIDMSG_DOT11REQ_MIBSET_RESULTCODE; 583 - resultcode->status = P80211ENUM_msgitem_status_no_value; 584 - resultcode->len = sizeof(resultcode->data); 585 - resultcode->data = 0; 586 - 587 - /* now fire the request */ 588 - result = p80211req_dorequest(dev->ml_priv, (u8 *)&dot11req); 589 - 590 - /* If the request wasn't successful, report an error and don't 591 - * change the netdev address 592 - */ 593 - if (result != 0 || resultcode->data != P80211ENUM_resultcode_success) { 594 - netdev_err(dev, "Low-level driver failed dot11req_mibset(dot11MACAddress).\n"); 595 - result = -EADDRNOTAVAIL; 596 - } else { 597 - /* everything's ok, change the addr in netdev */ 598 - eth_hw_addr_set(dev, new_addr->sa_data); 599 - } 600 - 601 - return result; 602 - } 603 - 604 - static const struct net_device_ops p80211_netdev_ops = { 605 - .ndo_init = p80211knetdev_init, 606 - .ndo_open = p80211knetdev_open, 607 - .ndo_stop = p80211knetdev_stop, 608 - .ndo_start_xmit = p80211knetdev_hard_start_xmit, 609 - .ndo_set_rx_mode = p80211knetdev_set_multicast_list, 610 - .ndo_siocdevprivate = p80211knetdev_siocdevprivate, 611 - .ndo_set_mac_address = p80211knetdev_set_mac_address, 612 - .ndo_tx_timeout = p80211knetdev_tx_timeout, 613 - .ndo_validate_addr = eth_validate_addr, 614 - }; 615 - 616 - /*---------------------------------------------------------------- 617 - * wlan_setup 618 - * 619 - * Roughly matches the functionality of ether_setup. Here 620 - * we set up any members of the wlandevice structure that are common 621 - * to all devices. Additionally, we allocate a linux 'struct device' 622 - * and perform the same setup as ether_setup. 623 - * 624 - * Note: It's important that the caller have setup the wlandev->name 625 - * ptr prior to calling this function. 626 - * 627 - * Arguments: 628 - * wlandev ptr to the wlandev structure for the 629 - * interface. 630 - * physdev ptr to usb device 631 - * Returns: 632 - * zero on success, non-zero otherwise. 633 - * Call Context: 634 - * Should be process thread. We'll assume it might be 635 - * interrupt though. When we add support for statically 636 - * compiled drivers, this function will be called in the 637 - * context of the kernel startup code. 638 - *---------------------------------------------------------------- 639 - */ 640 - int wlan_setup(struct wlandevice *wlandev, struct device *physdev) 641 - { 642 - int result = 0; 643 - struct net_device *netdev; 644 - struct wiphy *wiphy; 645 - struct wireless_dev *wdev; 646 - 647 - /* Set up the wlandev */ 648 - wlandev->state = WLAN_DEVICE_CLOSED; 649 - wlandev->ethconv = WLAN_ETHCONV_8021h; 650 - wlandev->macmode = WLAN_MACMODE_NONE; 651 - 652 - /* Set up the rx queue */ 653 - skb_queue_head_init(&wlandev->nsd_rxq); 654 - tasklet_setup(&wlandev->rx_bh, p80211netdev_rx_bh); 655 - 656 - /* Allocate and initialize the wiphy struct */ 657 - wiphy = wlan_create_wiphy(physdev, wlandev); 658 - if (!wiphy) { 659 - dev_err(physdev, "Failed to alloc wiphy.\n"); 660 - return 1; 661 - } 662 - 663 - /* Allocate and initialize the struct device */ 664 - netdev = alloc_netdev(sizeof(struct wireless_dev), "wlan%d", 665 - NET_NAME_UNKNOWN, ether_setup); 666 - if (!netdev) { 667 - dev_err(physdev, "Failed to alloc netdev.\n"); 668 - wlan_free_wiphy(wiphy); 669 - result = 1; 670 - } else { 671 - wlandev->netdev = netdev; 672 - netdev->ml_priv = wlandev; 673 - netdev->netdev_ops = &p80211_netdev_ops; 674 - wdev = netdev_priv(netdev); 675 - wdev->wiphy = wiphy; 676 - wdev->iftype = NL80211_IFTYPE_STATION; 677 - netdev->ieee80211_ptr = wdev; 678 - netdev->min_mtu = 68; 679 - /* 2312 is max 802.11 payload, 20 is overhead, 680 - * (ether + llc + snap) and another 8 for wep. 681 - */ 682 - netdev->max_mtu = (2312 - 20 - 8); 683 - 684 - netif_stop_queue(netdev); 685 - netif_carrier_off(netdev); 686 - } 687 - 688 - return result; 689 - } 690 - 691 - /*---------------------------------------------------------------- 692 - * wlan_unsetup 693 - * 694 - * This function is paired with the wlan_setup routine. It should 695 - * be called after unregister_wlandev. Basically, all it does is 696 - * free the 'struct device' that's associated with the wlandev. 697 - * We do it here because the 'struct device' isn't allocated 698 - * explicitly in the driver code, it's done in wlan_setup. To 699 - * do the free in the driver might seem like 'magic'. 700 - * 701 - * Arguments: 702 - * wlandev ptr to the wlandev structure for the 703 - * interface. 704 - * Call Context: 705 - * Should be process thread. We'll assume it might be 706 - * interrupt though. When we add support for statically 707 - * compiled drivers, this function will be called in the 708 - * context of the kernel startup code. 709 - *---------------------------------------------------------------- 710 - */ 711 - void wlan_unsetup(struct wlandevice *wlandev) 712 - { 713 - struct wireless_dev *wdev; 714 - 715 - tasklet_kill(&wlandev->rx_bh); 716 - 717 - if (wlandev->netdev) { 718 - wdev = netdev_priv(wlandev->netdev); 719 - if (wdev->wiphy) 720 - wlan_free_wiphy(wdev->wiphy); 721 - free_netdev(wlandev->netdev); 722 - wlandev->netdev = NULL; 723 - } 724 - } 725 - 726 - /*---------------------------------------------------------------- 727 - * register_wlandev 728 - * 729 - * Roughly matches the functionality of register_netdev. This function 730 - * is called after the driver has successfully probed and set up the 731 - * resources for the device. It's now ready to become a named device 732 - * in the Linux system. 733 - * 734 - * First we allocate a name for the device (if not already set), then 735 - * we call the Linux function register_netdevice. 736 - * 737 - * Arguments: 738 - * wlandev ptr to the wlandev structure for the 739 - * interface. 740 - * Returns: 741 - * zero on success, non-zero otherwise. 742 - * Call Context: 743 - * Can be either interrupt or not. 744 - *---------------------------------------------------------------- 745 - */ 746 - int register_wlandev(struct wlandevice *wlandev) 747 - { 748 - return register_netdev(wlandev->netdev); 749 - } 750 - 751 - /*---------------------------------------------------------------- 752 - * unregister_wlandev 753 - * 754 - * Roughly matches the functionality of unregister_netdev. This 755 - * function is called to remove a named device from the system. 756 - * 757 - * First we tell linux that the device should no longer exist. 758 - * Then we remove it from the list of known wlan devices. 759 - * 760 - * Arguments: 761 - * wlandev ptr to the wlandev structure for the 762 - * interface. 763 - * Returns: 764 - * zero on success, non-zero otherwise. 765 - * Call Context: 766 - * Can be either interrupt or not. 767 - *---------------------------------------------------------------- 768 - */ 769 - int unregister_wlandev(struct wlandevice *wlandev) 770 - { 771 - struct sk_buff *skb; 772 - 773 - unregister_netdev(wlandev->netdev); 774 - 775 - /* Now to clean out the rx queue */ 776 - while ((skb = skb_dequeue(&wlandev->nsd_rxq))) 777 - dev_kfree_skb(skb); 778 - 779 - return 0; 780 - } 781 - 782 - /*---------------------------------------------------------------- 783 - * p80211netdev_hwremoved 784 - * 785 - * Hardware removed notification. This function should be called 786 - * immediately after an MSD has detected that the underlying hardware 787 - * has been yanked out from under us. The primary things we need 788 - * to do are: 789 - * - Mark the wlandev 790 - * - Prevent any further traffic from the knetdev i/f 791 - * - Prevent any further requests from mgmt i/f 792 - * - If there are any waitq'd mgmt requests or mgmt-frame exchanges, 793 - * shut them down. 794 - * - Call the MSD hwremoved function. 795 - * 796 - * The remainder of the cleanup will be handled by unregister(). 797 - * Our primary goal here is to prevent as much tickling of the MSD 798 - * as possible since the MSD is already in a 'wounded' state. 799 - * 800 - * TODO: As new features are added, this function should be 801 - * updated. 802 - * 803 - * Arguments: 804 - * wlandev WLAN network device structure 805 - * Returns: 806 - * nothing 807 - * Side effects: 808 - * 809 - * Call context: 810 - * Usually interrupt. 811 - *---------------------------------------------------------------- 812 - */ 813 - void p80211netdev_hwremoved(struct wlandevice *wlandev) 814 - { 815 - wlandev->hwremoved = 1; 816 - if (wlandev->state == WLAN_DEVICE_OPEN) 817 - netif_stop_queue(wlandev->netdev); 818 - 819 - netif_device_detach(wlandev->netdev); 820 - } 821 - 822 - /*---------------------------------------------------------------- 823 - * p80211_rx_typedrop 824 - * 825 - * Classifies the frame, increments the appropriate counter, and 826 - * returns 0|1|2 indicating whether the driver should handle, ignore, or 827 - * drop the frame 828 - * 829 - * Arguments: 830 - * wlandev wlan device structure 831 - * fc frame control field 832 - * 833 - * Returns: 834 - * zero if the frame should be handled by the driver, 835 - * one if the frame should be ignored 836 - * anything else means we drop it. 837 - * 838 - * Side effects: 839 - * 840 - * Call context: 841 - * interrupt 842 - *---------------------------------------------------------------- 843 - */ 844 - static int p80211_rx_typedrop(struct wlandevice *wlandev, u16 fc) 845 - { 846 - u16 ftype; 847 - u16 fstype; 848 - int drop = 0; 849 - /* Classify frame, increment counter */ 850 - ftype = WLAN_GET_FC_FTYPE(fc); 851 - fstype = WLAN_GET_FC_FSTYPE(fc); 852 - switch (ftype) { 853 - case WLAN_FTYPE_MGMT: 854 - if ((wlandev->netdev->flags & IFF_PROMISC) || 855 - (wlandev->netdev->flags & IFF_ALLMULTI)) { 856 - drop = 1; 857 - break; 858 - } 859 - netdev_dbg(wlandev->netdev, "rx'd mgmt:\n"); 860 - wlandev->rx.mgmt++; 861 - switch (fstype) { 862 - case WLAN_FSTYPE_ASSOCREQ: 863 - wlandev->rx.assocreq++; 864 - break; 865 - case WLAN_FSTYPE_ASSOCRESP: 866 - wlandev->rx.assocresp++; 867 - break; 868 - case WLAN_FSTYPE_REASSOCREQ: 869 - wlandev->rx.reassocreq++; 870 - break; 871 - case WLAN_FSTYPE_REASSOCRESP: 872 - wlandev->rx.reassocresp++; 873 - break; 874 - case WLAN_FSTYPE_PROBEREQ: 875 - wlandev->rx.probereq++; 876 - break; 877 - case WLAN_FSTYPE_PROBERESP: 878 - wlandev->rx.proberesp++; 879 - break; 880 - case WLAN_FSTYPE_BEACON: 881 - wlandev->rx.beacon++; 882 - break; 883 - case WLAN_FSTYPE_ATIM: 884 - wlandev->rx.atim++; 885 - break; 886 - case WLAN_FSTYPE_DISASSOC: 887 - wlandev->rx.disassoc++; 888 - break; 889 - case WLAN_FSTYPE_AUTHEN: 890 - wlandev->rx.authen++; 891 - break; 892 - case WLAN_FSTYPE_DEAUTHEN: 893 - wlandev->rx.deauthen++; 894 - break; 895 - default: 896 - wlandev->rx.mgmt_unknown++; 897 - break; 898 - } 899 - drop = 2; 900 - break; 901 - 902 - case WLAN_FTYPE_CTL: 903 - if ((wlandev->netdev->flags & IFF_PROMISC) || 904 - (wlandev->netdev->flags & IFF_ALLMULTI)) { 905 - drop = 1; 906 - break; 907 - } 908 - netdev_dbg(wlandev->netdev, "rx'd ctl:\n"); 909 - wlandev->rx.ctl++; 910 - switch (fstype) { 911 - case WLAN_FSTYPE_PSPOLL: 912 - wlandev->rx.pspoll++; 913 - break; 914 - case WLAN_FSTYPE_RTS: 915 - wlandev->rx.rts++; 916 - break; 917 - case WLAN_FSTYPE_CTS: 918 - wlandev->rx.cts++; 919 - break; 920 - case WLAN_FSTYPE_ACK: 921 - wlandev->rx.ack++; 922 - break; 923 - case WLAN_FSTYPE_CFEND: 924 - wlandev->rx.cfend++; 925 - break; 926 - case WLAN_FSTYPE_CFENDCFACK: 927 - wlandev->rx.cfendcfack++; 928 - break; 929 - default: 930 - wlandev->rx.ctl_unknown++; 931 - break; 932 - } 933 - drop = 2; 934 - break; 935 - 936 - case WLAN_FTYPE_DATA: 937 - wlandev->rx.data++; 938 - switch (fstype) { 939 - case WLAN_FSTYPE_DATAONLY: 940 - wlandev->rx.dataonly++; 941 - break; 942 - case WLAN_FSTYPE_DATA_CFACK: 943 - wlandev->rx.data_cfack++; 944 - break; 945 - case WLAN_FSTYPE_DATA_CFPOLL: 946 - wlandev->rx.data_cfpoll++; 947 - break; 948 - case WLAN_FSTYPE_DATA_CFACK_CFPOLL: 949 - wlandev->rx.data__cfack_cfpoll++; 950 - break; 951 - case WLAN_FSTYPE_NULL: 952 - netdev_dbg(wlandev->netdev, "rx'd data:null\n"); 953 - wlandev->rx.null++; 954 - break; 955 - case WLAN_FSTYPE_CFACK: 956 - netdev_dbg(wlandev->netdev, "rx'd data:cfack\n"); 957 - wlandev->rx.cfack++; 958 - break; 959 - case WLAN_FSTYPE_CFPOLL: 960 - netdev_dbg(wlandev->netdev, "rx'd data:cfpoll\n"); 961 - wlandev->rx.cfpoll++; 962 - break; 963 - case WLAN_FSTYPE_CFACK_CFPOLL: 964 - netdev_dbg(wlandev->netdev, "rx'd data:cfack_cfpoll\n"); 965 - wlandev->rx.cfack_cfpoll++; 966 - break; 967 - default: 968 - wlandev->rx.data_unknown++; 969 - break; 970 - } 971 - 972 - break; 973 - } 974 - return drop; 975 - } 976 - 977 - static void p80211knetdev_tx_timeout(struct net_device *netdev, unsigned int txqueue) 978 - { 979 - struct wlandevice *wlandev = netdev->ml_priv; 980 - 981 - if (wlandev->tx_timeout) { 982 - wlandev->tx_timeout(wlandev); 983 - } else { 984 - netdev_warn(netdev, "Implement tx_timeout for %s\n", 985 - wlandev->nsdname); 986 - netif_wake_queue(wlandev->netdev); 987 - } 988 - }
-212
drivers/staging/wlan-ng/p80211netdev.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * WLAN net device structure and functions 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file declares the structure type that represents each wlan 28 - * interface. 29 - * 30 - * -------------------------------------------------------------------- 31 - */ 32 - 33 - #ifndef _LINUX_P80211NETDEV_H 34 - #define _LINUX_P80211NETDEV_H 35 - 36 - #include <linux/interrupt.h> 37 - #include <linux/wireless.h> 38 - #include <linux/netdevice.h> 39 - 40 - #define WLAN_RELEASE "0.3.0-staging" 41 - 42 - #define WLAN_DEVICE_CLOSED 0 43 - #define WLAN_DEVICE_OPEN 1 44 - 45 - #define WLAN_MACMODE_NONE 0 46 - #define WLAN_MACMODE_IBSS_STA 1 47 - #define WLAN_MACMODE_ESS_STA 2 48 - #define WLAN_MACMODE_ESS_AP 3 49 - 50 - /* MSD States */ 51 - #define WLAN_MSD_HWPRESENT_PENDING 1 52 - #define WLAN_MSD_HWFAIL 2 53 - #define WLAN_MSD_HWPRESENT 3 54 - #define WLAN_MSD_FWLOAD_PENDING 4 55 - #define WLAN_MSD_FWLOAD 5 56 - #define WLAN_MSD_RUNNING_PENDING 6 57 - #define WLAN_MSD_RUNNING 7 58 - 59 - #ifndef ETH_P_ECONET 60 - #define ETH_P_ECONET 0x0018 /* needed for 2.2.x kernels */ 61 - #endif 62 - 63 - #define ETH_P_80211_RAW (ETH_P_ECONET + 1) 64 - 65 - #ifndef ARPHRD_IEEE80211 66 - #define ARPHRD_IEEE80211 801 /* kernel 2.4.6 */ 67 - #endif 68 - 69 - #ifndef ARPHRD_IEEE80211_PRISM /* kernel 2.4.18 */ 70 - #define ARPHRD_IEEE80211_PRISM 802 71 - #endif 72 - 73 - /*--- NSD Capabilities Flags ------------------------------*/ 74 - #define P80211_NSDCAP_HARDWAREWEP 0x01 /* hardware wep engine */ 75 - #define P80211_NSDCAP_SHORT_PREAMBLE 0x10 /* hardware supports */ 76 - #define P80211_NSDCAP_HWFRAGMENT 0x80 /* nsd handles frag/defrag */ 77 - #define P80211_NSDCAP_AUTOJOIN 0x100 /* nsd does autojoin */ 78 - #define P80211_NSDCAP_NOSCAN 0x200 /* nsd can scan */ 79 - 80 - /* Received frame statistics */ 81 - struct p80211_frmrx { 82 - u32 mgmt; 83 - u32 assocreq; 84 - u32 assocresp; 85 - u32 reassocreq; 86 - u32 reassocresp; 87 - u32 probereq; 88 - u32 proberesp; 89 - u32 beacon; 90 - u32 atim; 91 - u32 disassoc; 92 - u32 authen; 93 - u32 deauthen; 94 - u32 mgmt_unknown; 95 - u32 ctl; 96 - u32 pspoll; 97 - u32 rts; 98 - u32 cts; 99 - u32 ack; 100 - u32 cfend; 101 - u32 cfendcfack; 102 - u32 ctl_unknown; 103 - u32 data; 104 - u32 dataonly; 105 - u32 data_cfack; 106 - u32 data_cfpoll; 107 - u32 data__cfack_cfpoll; 108 - u32 null; 109 - u32 cfack; 110 - u32 cfpoll; 111 - u32 cfack_cfpoll; 112 - u32 data_unknown; 113 - u32 decrypt; 114 - u32 decrypt_err; 115 - }; 116 - 117 - /* WEP stuff */ 118 - #define NUM_WEPKEYS 4 119 - #define MAX_KEYLEN 32 120 - 121 - #define HOSTWEP_DEFAULTKEY_MASK GENMASK(1, 0) 122 - #define HOSTWEP_SHAREDKEY BIT(3) 123 - #define HOSTWEP_DECRYPT BIT(4) 124 - #define HOSTWEP_ENCRYPT BIT(5) 125 - #define HOSTWEP_PRIVACYINVOKED BIT(6) 126 - #define HOSTWEP_EXCLUDEUNENCRYPTED BIT(7) 127 - 128 - extern int wlan_watchdog; 129 - extern int wlan_wext_write; 130 - 131 - /* WLAN device type */ 132 - struct wlandevice { 133 - void *priv; /* private data for MSD */ 134 - 135 - /* Subsystem State */ 136 - char name[WLAN_DEVNAMELEN_MAX]; /* Dev name, from register_wlandev() */ 137 - char *nsdname; 138 - 139 - u32 state; /* Device I/F state (open/closed) */ 140 - u32 msdstate; /* state of underlying driver */ 141 - u32 hwremoved; /* Has the hw been yanked out? */ 142 - 143 - /* Hardware config */ 144 - unsigned int irq; 145 - unsigned int iobase; 146 - unsigned int membase; 147 - u32 nsdcaps; /* NSD Capabilities flags */ 148 - 149 - /* Config vars */ 150 - unsigned int ethconv; 151 - 152 - /* device methods (init by MSD, used by p80211 */ 153 - int (*open)(struct wlandevice *wlandev); 154 - int (*close)(struct wlandevice *wlandev); 155 - void (*reset)(struct wlandevice *wlandev); 156 - int (*txframe)(struct wlandevice *wlandev, struct sk_buff *skb, 157 - struct p80211_hdr *p80211_hdr, 158 - struct p80211_metawep *p80211_wep); 159 - int (*mlmerequest)(struct wlandevice *wlandev, struct p80211msg *msg); 160 - int (*set_multicast_list)(struct wlandevice *wlandev, 161 - struct net_device *dev); 162 - void (*tx_timeout)(struct wlandevice *wlandev); 163 - 164 - /* 802.11 State */ 165 - u8 bssid[WLAN_BSSID_LEN]; 166 - struct p80211pstr32 ssid; 167 - u32 macmode; 168 - int linkstatus; 169 - 170 - /* WEP State */ 171 - u8 wep_keys[NUM_WEPKEYS][MAX_KEYLEN]; 172 - u8 wep_keylens[NUM_WEPKEYS]; 173 - int hostwep; 174 - 175 - /* Request/Confirm i/f state (used by p80211) */ 176 - unsigned long request_pending; /* flag, access atomically */ 177 - 178 - /* netlink socket */ 179 - /* queue for indications waiting for cmd completion */ 180 - /* Linux netdevice and support */ 181 - struct net_device *netdev; /* ptr to linux netdevice */ 182 - 183 - /* Rx bottom half */ 184 - struct tasklet_struct rx_bh; 185 - 186 - struct sk_buff_head nsd_rxq; 187 - 188 - /* 802.11 device statistics */ 189 - struct p80211_frmrx rx; 190 - 191 - struct iw_statistics wstats; 192 - 193 - /* jkriegl: iwspy fields */ 194 - u8 spy_number; 195 - char spy_address[IW_MAX_SPY][ETH_ALEN]; 196 - struct iw_quality spy_stat[IW_MAX_SPY]; 197 - }; 198 - 199 - /* WEP stuff */ 200 - int wep_change_key(struct wlandevice *wlandev, int keynum, u8 *key, int keylen); 201 - int wep_decrypt(struct wlandevice *wlandev, u8 *buf, u32 len, int key_override, 202 - u8 *iv, u8 *icv); 203 - int wep_encrypt(struct wlandevice *wlandev, u8 *buf, u8 *dst, u32 len, 204 - int keynum, u8 *iv, u8 *icv); 205 - 206 - int wlan_setup(struct wlandevice *wlandev, struct device *physdev); 207 - void wlan_unsetup(struct wlandevice *wlandev); 208 - int register_wlandev(struct wlandevice *wlandev); 209 - int unregister_wlandev(struct wlandevice *wlandev); 210 - void p80211netdev_rx(struct wlandevice *wlandev, struct sk_buff *skb); 211 - void p80211netdev_hwremoved(struct wlandevice *wlandev); 212 - #endif
-223
drivers/staging/wlan-ng/p80211req.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Request/Indication/MacMgmt interface handling functions 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file contains the functions, types, and macros to support the 28 - * MLME request interface that's implemented via the device ioctls. 29 - * 30 - * -------------------------------------------------------------------- 31 - */ 32 - 33 - #include <linux/module.h> 34 - #include <linux/kernel.h> 35 - #include <linux/sched.h> 36 - #include <linux/types.h> 37 - #include <linux/skbuff.h> 38 - #include <linux/wireless.h> 39 - #include <linux/netdevice.h> 40 - #include <linux/etherdevice.h> 41 - #include <net/sock.h> 42 - #include <linux/netlink.h> 43 - 44 - #include "p80211types.h" 45 - #include "p80211hdr.h" 46 - #include "p80211mgmt.h" 47 - #include "p80211conv.h" 48 - #include "p80211msg.h" 49 - #include "p80211netdev.h" 50 - #include "p80211ioctl.h" 51 - #include "p80211metadef.h" 52 - #include "p80211metastruct.h" 53 - #include "p80211req.h" 54 - 55 - static void p80211req_handlemsg(struct wlandevice *wlandev, 56 - struct p80211msg *msg); 57 - static void p80211req_mibset_mibget(struct wlandevice *wlandev, 58 - struct p80211msg_dot11req_mibget *mib_msg, 59 - int isget); 60 - 61 - static void p80211req_handle_action(struct wlandevice *wlandev, u32 *data, 62 - int isget, u32 flag) 63 - { 64 - if (isget) { 65 - if (wlandev->hostwep & flag) 66 - *data = P80211ENUM_truth_true; 67 - else 68 - *data = P80211ENUM_truth_false; 69 - } else { 70 - wlandev->hostwep &= ~flag; 71 - if (*data == P80211ENUM_truth_true) 72 - wlandev->hostwep |= flag; 73 - } 74 - } 75 - 76 - /*---------------------------------------------------------------- 77 - * p80211req_dorequest 78 - * 79 - * Handles an MLME request/confirm message. 80 - * 81 - * Arguments: 82 - * wlandev WLAN device struct 83 - * msgbuf Buffer containing a request message 84 - * 85 - * Returns: 86 - * 0 on success, an errno otherwise 87 - * 88 - * Call context: 89 - * Potentially blocks the caller, so it's a good idea to 90 - * not call this function from an interrupt context. 91 - *---------------------------------------------------------------- 92 - */ 93 - int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf) 94 - { 95 - struct p80211msg *msg = (struct p80211msg *)msgbuf; 96 - 97 - /* Check to make sure the MSD is running */ 98 - if (!((wlandev->msdstate == WLAN_MSD_HWPRESENT && 99 - msg->msgcode == DIDMSG_LNXREQ_IFSTATE) || 100 - wlandev->msdstate == WLAN_MSD_RUNNING || 101 - wlandev->msdstate == WLAN_MSD_FWLOAD)) { 102 - return -ENODEV; 103 - } 104 - 105 - /* Check Permissions */ 106 - if (!capable(CAP_NET_ADMIN) && 107 - (msg->msgcode != DIDMSG_DOT11REQ_MIBGET)) { 108 - netdev_err(wlandev->netdev, 109 - "%s: only dot11req_mibget allowed for non-root.\n", 110 - wlandev->name); 111 - return -EPERM; 112 - } 113 - 114 - /* Check for busy status */ 115 - if (test_and_set_bit(1, &wlandev->request_pending)) 116 - return -EBUSY; 117 - 118 - /* Allow p80211 to look at msg and handle if desired. */ 119 - /* So far, all p80211 msgs are immediate, no waitq/timer necessary */ 120 - /* This may change. */ 121 - p80211req_handlemsg(wlandev, msg); 122 - 123 - /* Pass it down to wlandev via wlandev->mlmerequest */ 124 - if (wlandev->mlmerequest) 125 - wlandev->mlmerequest(wlandev, msg); 126 - 127 - clear_bit(1, &wlandev->request_pending); 128 - return 0; /* if result==0, msg->status still may contain an err */ 129 - } 130 - 131 - /*---------------------------------------------------------------- 132 - * p80211req_handlemsg 133 - * 134 - * p80211 message handler. Primarily looks for messages that 135 - * belong to p80211 and then dispatches the appropriate response. 136 - * TODO: we don't do anything yet. Once the linuxMIB is better 137 - * defined we'll need a get/set handler. 138 - * 139 - * Arguments: 140 - * wlandev WLAN device struct 141 - * msg message structure 142 - * 143 - * Returns: 144 - * nothing (any results are set in the status field of the msg) 145 - * 146 - * Call context: 147 - * Process thread 148 - *---------------------------------------------------------------- 149 - */ 150 - static void p80211req_handlemsg(struct wlandevice *wlandev, 151 - struct p80211msg *msg) 152 - { 153 - switch (msg->msgcode) { 154 - case DIDMSG_LNXREQ_HOSTWEP: { 155 - struct p80211msg_lnxreq_hostwep *req = 156 - (struct p80211msg_lnxreq_hostwep *)msg; 157 - wlandev->hostwep &= 158 - ~(HOSTWEP_DECRYPT | HOSTWEP_ENCRYPT); 159 - if (req->decrypt.data == P80211ENUM_truth_true) 160 - wlandev->hostwep |= HOSTWEP_DECRYPT; 161 - if (req->encrypt.data == P80211ENUM_truth_true) 162 - wlandev->hostwep |= HOSTWEP_ENCRYPT; 163 - 164 - break; 165 - } 166 - case DIDMSG_DOT11REQ_MIBGET: 167 - case DIDMSG_DOT11REQ_MIBSET: { 168 - int isget = (msg->msgcode == DIDMSG_DOT11REQ_MIBGET); 169 - struct p80211msg_dot11req_mibget *mib_msg = 170 - (struct p80211msg_dot11req_mibget *)msg; 171 - p80211req_mibset_mibget(wlandev, mib_msg, isget); 172 - break; 173 - } 174 - } /* switch msg->msgcode */ 175 - } 176 - 177 - static void p80211req_mibset_mibget(struct wlandevice *wlandev, 178 - struct p80211msg_dot11req_mibget *mib_msg, 179 - int isget) 180 - { 181 - struct p80211itemd *mibitem = 182 - (struct p80211itemd *)mib_msg->mibattribute.data; 183 - struct p80211pstrd *pstr = (struct p80211pstrd *)mibitem->data; 184 - u8 *key = mibitem->data + sizeof(struct p80211pstrd); 185 - 186 - switch (mibitem->did) { 187 - case didmib_dot11smt_wepdefaultkeystable_key(1): 188 - case didmib_dot11smt_wepdefaultkeystable_key(2): 189 - case didmib_dot11smt_wepdefaultkeystable_key(3): 190 - case didmib_dot11smt_wepdefaultkeystable_key(4): 191 - if (!isget) 192 - wep_change_key(wlandev, 193 - P80211DID_ITEM(mibitem->did) - 1, 194 - key, pstr->len); 195 - break; 196 - 197 - case DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID: { 198 - u32 *data = (u32 *)mibitem->data; 199 - 200 - if (isget) { 201 - *data = wlandev->hostwep & HOSTWEP_DEFAULTKEY_MASK; 202 - } else { 203 - wlandev->hostwep &= ~(HOSTWEP_DEFAULTKEY_MASK); 204 - wlandev->hostwep |= (*data & HOSTWEP_DEFAULTKEY_MASK); 205 - } 206 - break; 207 - } 208 - case DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED: { 209 - u32 *data = (u32 *)mibitem->data; 210 - 211 - p80211req_handle_action(wlandev, data, isget, 212 - HOSTWEP_PRIVACYINVOKED); 213 - break; 214 - } 215 - case DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED: { 216 - u32 *data = (u32 *)mibitem->data; 217 - 218 - p80211req_handle_action(wlandev, data, isget, 219 - HOSTWEP_EXCLUDEUNENCRYPTED); 220 - break; 221 - } 222 - } 223 - }
-33
drivers/staging/wlan-ng/p80211req.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Request handling functions 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - */ 27 - 28 - #ifndef _LINUX_P80211REQ_H 29 - #define _LINUX_P80211REQ_H 30 - 31 - int p80211req_dorequest(struct wlandevice *wlandev, u8 *msgbuf); 32 - 33 - #endif
-292
drivers/staging/wlan-ng/p80211types.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * 5 - * Macros, constants, types, and funcs for p80211 data types 6 - * 7 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 8 - * -------------------------------------------------------------------- 9 - * 10 - * linux-wlan 11 - * 12 - * -------------------------------------------------------------------- 13 - * 14 - * Inquiries regarding the linux-wlan Open Source project can be 15 - * made directly to: 16 - * 17 - * AbsoluteValue Systems Inc. 18 - * info@linux-wlan.com 19 - * http://www.linux-wlan.com 20 - * 21 - * -------------------------------------------------------------------- 22 - * 23 - * Portions of the development of this software were funded by 24 - * Intersil Corporation as part of PRISM(R) chipset product development. 25 - * 26 - * -------------------------------------------------------------------- 27 - * 28 - * This file declares some of the constants and types used in various 29 - * parts of the linux-wlan system. 30 - * 31 - * Notes: 32 - * - Constant values are always in HOST byte order. 33 - * 34 - * All functions and statics declared here are implemented in p80211types.c 35 - * -------------------------------------------------------------------- 36 - */ 37 - 38 - #ifndef _P80211TYPES_H 39 - #define _P80211TYPES_H 40 - 41 - /*----------------------------------------------------------------*/ 42 - /* The following constants are indexes into the Mib Category List */ 43 - /* and the Message Category List */ 44 - 45 - /* Mib Category List */ 46 - #define P80211_MIB_CAT_DOT11SMT 1 47 - #define P80211_MIB_CAT_DOT11MAC 2 48 - #define P80211_MIB_CAT_DOT11PHY 3 49 - 50 - #define P80211SEC_DOT11SMT P80211_MIB_CAT_DOT11SMT 51 - #define P80211SEC_DOT11MAC P80211_MIB_CAT_DOT11MAC 52 - #define P80211SEC_DOT11PHY P80211_MIB_CAT_DOT11PHY 53 - 54 - /* Message Category List */ 55 - #define P80211_MSG_CAT_DOT11REQ 1 56 - #define P80211_MSG_CAT_DOT11IND 2 57 - 58 - /*----------------------------------------------------------------*/ 59 - /* p80211 enumeration constants. The value to text mappings for */ 60 - /* these is in p80211types.c. These defines were generated */ 61 - /* from the mappings. */ 62 - 63 - /* error codes for lookups */ 64 - 65 - #define P80211ENUM_truth_false 0 66 - #define P80211ENUM_truth_true 1 67 - #define P80211ENUM_ifstate_disable 0 68 - #define P80211ENUM_ifstate_fwload 1 69 - #define P80211ENUM_ifstate_enable 2 70 - #define P80211ENUM_bsstype_infrastructure 1 71 - #define P80211ENUM_bsstype_independent 2 72 - #define P80211ENUM_bsstype_any 3 73 - #define P80211ENUM_authalg_opensystem 1 74 - #define P80211ENUM_authalg_sharedkey 2 75 - #define P80211ENUM_scantype_active 1 76 - #define P80211ENUM_resultcode_success 1 77 - #define P80211ENUM_resultcode_invalid_parameters 2 78 - #define P80211ENUM_resultcode_not_supported 3 79 - #define P80211ENUM_resultcode_refused 6 80 - #define P80211ENUM_resultcode_cant_set_readonly_mib 10 81 - #define P80211ENUM_resultcode_implementation_failure 11 82 - #define P80211ENUM_resultcode_cant_get_writeonly_mib 12 83 - #define P80211ENUM_status_successful 0 84 - #define P80211ENUM_status_unspec_failure 1 85 - #define P80211ENUM_status_ap_full 17 86 - #define P80211ENUM_msgitem_status_data_ok 0 87 - #define P80211ENUM_msgitem_status_no_value 1 88 - 89 - /*----------------------------------------------------------------*/ 90 - /* p80211 max length constants for the different pascal strings. */ 91 - 92 - #define MAXLEN_PSTR6 (6) /* pascal array of 6 bytes */ 93 - #define MAXLEN_PSTR14 (14) /* pascal array of 14 bytes */ 94 - #define MAXLEN_PSTR32 (32) /* pascal array of 32 bytes */ 95 - #define MAXLEN_PSTR255 (255) /* pascal array of 255 bytes */ 96 - #define MAXLEN_MIBATTRIBUTE (392) /* maximum mibattribute */ 97 - /* where the size of the DATA itself */ 98 - /* is a DID-LEN-DATA triple */ 99 - /* with a max size of 4+4+384 */ 100 - 101 - /*---------------------------------------------------------------- 102 - * The following constants and macros are used to construct and 103 - * deconstruct the Data ID codes. The coding is as follows: 104 - * 105 - * ...rwtnnnnnnnniiiiiiggggggssssss s - Section 106 - * g - Group 107 - * i - Item 108 - * n - Index 109 - * t - Table flag 110 - * w - Write flag 111 - * r - Read flag 112 - * . - Unused 113 - */ 114 - 115 - #define P80211DID_LSB_SECTION (0) 116 - #define P80211DID_LSB_GROUP (6) 117 - #define P80211DID_LSB_ITEM (12) 118 - #define P80211DID_LSB_INDEX (18) 119 - #define P80211DID_LSB_ISTABLE (26) 120 - #define P80211DID_LSB_ACCESS (27) 121 - 122 - #define P80211DID_MASK_SECTION (0x0000003fUL) 123 - #define P80211DID_MASK_GROUP (0x0000003fUL) 124 - #define P80211DID_MASK_ITEM (0x0000003fUL) 125 - #define P80211DID_MASK_INDEX (0x000000ffUL) 126 - #define P80211DID_MASK_ISTABLE (0x00000001UL) 127 - #define P80211DID_MASK_ACCESS (0x00000003UL) 128 - 129 - #define P80211DID_MK(a, m, l) ((((u32)(a)) & (m)) << (l)) 130 - 131 - #define P80211DID_MKSECTION(a) P80211DID_MK(a, \ 132 - P80211DID_MASK_SECTION, \ 133 - P80211DID_LSB_SECTION) 134 - #define P80211DID_MKGROUP(a) P80211DID_MK(a, \ 135 - P80211DID_MASK_GROUP, \ 136 - P80211DID_LSB_GROUP) 137 - #define P80211DID_MKITEM(a) P80211DID_MK(a, \ 138 - P80211DID_MASK_ITEM, \ 139 - P80211DID_LSB_ITEM) 140 - #define P80211DID_MKINDEX(a) P80211DID_MK(a, \ 141 - P80211DID_MASK_INDEX, \ 142 - P80211DID_LSB_INDEX) 143 - #define P80211DID_MKISTABLE(a) P80211DID_MK(a, \ 144 - P80211DID_MASK_ISTABLE, \ 145 - P80211DID_LSB_ISTABLE) 146 - 147 - #define P80211DID_MKID(s, g, i, n, t, a) (P80211DID_MKSECTION(s) | \ 148 - P80211DID_MKGROUP(g) | \ 149 - P80211DID_MKITEM(i) | \ 150 - P80211DID_MKINDEX(n) | \ 151 - P80211DID_MKISTABLE(t) | \ 152 - (a)) 153 - 154 - #define P80211DID_GET(a, m, l) ((((u32)(a)) >> (l)) & (m)) 155 - 156 - #define P80211DID_SECTION(a) P80211DID_GET(a, \ 157 - P80211DID_MASK_SECTION, \ 158 - P80211DID_LSB_SECTION) 159 - #define P80211DID_GROUP(a) P80211DID_GET(a, \ 160 - P80211DID_MASK_GROUP, \ 161 - P80211DID_LSB_GROUP) 162 - #define P80211DID_ITEM(a) P80211DID_GET(a, \ 163 - P80211DID_MASK_ITEM, \ 164 - P80211DID_LSB_ITEM) 165 - #define P80211DID_INDEX(a) P80211DID_GET(a, \ 166 - P80211DID_MASK_INDEX, \ 167 - P80211DID_LSB_INDEX) 168 - #define P80211DID_ISTABLE(a) P80211DID_GET(a, \ 169 - P80211DID_MASK_ISTABLE, \ 170 - P80211DID_LSB_ISTABLE) 171 - #define P80211DID_ACCESS(a) P80211DID_GET(a, \ 172 - P80211DID_MASK_ACCESS, \ 173 - P80211DID_LSB_ACCESS) 174 - 175 - /*----------------------------------------------------------------*/ 176 - /* The following structure types are used to store data items in */ 177 - /* messages. */ 178 - 179 - /* Template pascal string */ 180 - struct p80211pstr { 181 - u8 len; 182 - } __packed; 183 - 184 - struct p80211pstrd { 185 - u8 len; 186 - u8 data[]; 187 - } __packed; 188 - 189 - /* Maximum pascal string */ 190 - struct p80211pstr255 { 191 - u8 len; 192 - u8 data[MAXLEN_PSTR255]; 193 - } __packed; 194 - 195 - /* pascal string for macaddress and bssid */ 196 - struct p80211pstr6 { 197 - u8 len; 198 - u8 data[MAXLEN_PSTR6]; 199 - } __packed; 200 - 201 - /* pascal string for channel list */ 202 - struct p80211pstr14 { 203 - u8 len; 204 - u8 data[MAXLEN_PSTR14]; 205 - } __packed; 206 - 207 - /* pascal string for ssid */ 208 - struct p80211pstr32 { 209 - u8 len; 210 - u8 data[MAXLEN_PSTR32]; 211 - } __packed; 212 - 213 - /* prototype template */ 214 - struct p80211item { 215 - u32 did; 216 - u16 status; 217 - u16 len; 218 - } __packed; 219 - 220 - /* prototype template w/ data item */ 221 - struct p80211itemd { 222 - u32 did; 223 - u16 status; 224 - u16 len; 225 - u8 data[]; 226 - } __packed; 227 - 228 - /* message data item for int, BOUNDEDINT, ENUMINT */ 229 - struct p80211item_uint32 { 230 - u32 did; 231 - u16 status; 232 - u16 len; 233 - u32 data; 234 - } __packed; 235 - 236 - /* message data item for OCTETSTR, DISPLAYSTR */ 237 - struct p80211item_pstr6 { 238 - u32 did; 239 - u16 status; 240 - u16 len; 241 - struct p80211pstr6 data; 242 - } __packed; 243 - 244 - /* message data item for OCTETSTR, DISPLAYSTR */ 245 - struct p80211item_pstr14 { 246 - u32 did; 247 - u16 status; 248 - u16 len; 249 - struct p80211pstr14 data; 250 - } __packed; 251 - 252 - /* message data item for OCTETSTR, DISPLAYSTR */ 253 - struct p80211item_pstr32 { 254 - u32 did; 255 - u16 status; 256 - u16 len; 257 - struct p80211pstr32 data; 258 - } __packed; 259 - 260 - /* message data item for OCTETSTR, DISPLAYSTR */ 261 - struct p80211item_pstr255 { 262 - u32 did; 263 - u16 status; 264 - u16 len; 265 - struct p80211pstr255 data; 266 - } __packed; 267 - 268 - /* message data item for UNK 392, namely mib items */ 269 - struct p80211item_unk392 { 270 - u32 did; 271 - u16 status; 272 - u16 len; 273 - u8 data[MAXLEN_MIBATTRIBUTE]; 274 - } __packed; 275 - 276 - /* message data item for UNK 1025, namely p2 pdas */ 277 - struct p80211item_unk1024 { 278 - u32 did; 279 - u16 status; 280 - u16 len; 281 - u8 data[1024]; 282 - } __packed; 283 - 284 - /* message data item for UNK 4096, namely p2 download chunks */ 285 - struct p80211item_unk4096 { 286 - u32 did; 287 - u16 status; 288 - u16 len; 289 - u8 data[4096]; 290 - } __packed; 291 - 292 - #endif /* _P80211TYPES_H */
-207
drivers/staging/wlan-ng/p80211wep.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * WEP encode/decode for P80211. 5 - * 6 - * Copyright (C) 2002 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - */ 27 - 28 - /*================================================================*/ 29 - /* System Includes */ 30 - 31 - #include <linux/crc32.h> 32 - #include <linux/netdevice.h> 33 - #include <linux/wireless.h> 34 - #include <linux/random.h> 35 - #include <linux/kernel.h> 36 - #include "p80211hdr.h" 37 - #include "p80211types.h" 38 - #include "p80211msg.h" 39 - #include "p80211conv.h" 40 - #include "p80211netdev.h" 41 - 42 - #define WEP_KEY(x) (((x) & 0xC0) >> 6) 43 - 44 - /* keylen in bytes! */ 45 - 46 - int wep_change_key(struct wlandevice *wlandev, int keynum, u8 *key, int keylen) 47 - { 48 - if (keylen < 0) 49 - return -1; 50 - if (keylen >= MAX_KEYLEN) 51 - return -1; 52 - if (!key) 53 - return -1; 54 - if (keynum < 0) 55 - return -1; 56 - if (keynum >= NUM_WEPKEYS) 57 - return -1; 58 - 59 - wlandev->wep_keylens[keynum] = keylen; 60 - memcpy(wlandev->wep_keys[keynum], key, keylen); 61 - 62 - return 0; 63 - } 64 - 65 - /* 66 - * 4-byte IV at start of buffer, 4-byte ICV at end of buffer. 67 - * if successful, buf start is payload begin, length -= 8; 68 - */ 69 - int wep_decrypt(struct wlandevice *wlandev, u8 *buf, u32 len, int key_override, 70 - u8 *iv, u8 *icv) 71 - { 72 - u32 i, j, k, crc, keylen; 73 - u8 s[256], key[64], c_crc[4]; 74 - u8 keyidx; 75 - 76 - /* Needs to be at least 8 bytes of payload */ 77 - if (len <= 0) 78 - return -1; 79 - 80 - /* initialize the first bytes of the key from the IV */ 81 - key[0] = iv[0]; 82 - key[1] = iv[1]; 83 - key[2] = iv[2]; 84 - keyidx = WEP_KEY(iv[3]); 85 - 86 - if (key_override >= 0) 87 - keyidx = key_override; 88 - 89 - if (keyidx >= NUM_WEPKEYS) 90 - return -2; 91 - 92 - keylen = wlandev->wep_keylens[keyidx]; 93 - 94 - if (keylen == 0) 95 - return -3; 96 - 97 - /* copy the rest of the key over from the designated key */ 98 - memcpy(key + 3, wlandev->wep_keys[keyidx], keylen); 99 - 100 - keylen += 3; /* add in IV bytes */ 101 - 102 - /* set up the RC4 state */ 103 - for (i = 0; i < 256; i++) 104 - s[i] = i; 105 - j = 0; 106 - for (i = 0; i < 256; i++) { 107 - j = (j + s[i] + key[i % keylen]) & 0xff; 108 - swap(i, j); 109 - } 110 - 111 - /* Apply the RC4 to the data, update the CRC32 */ 112 - i = 0; 113 - j = 0; 114 - for (k = 0; k < len; k++) { 115 - i = (i + 1) & 0xff; 116 - j = (j + s[i]) & 0xff; 117 - swap(i, j); 118 - buf[k] ^= s[(s[i] + s[j]) & 0xff]; 119 - } 120 - crc = ~crc32_le(~0, buf, len); 121 - 122 - /* now let's check the crc */ 123 - c_crc[0] = crc; 124 - c_crc[1] = crc >> 8; 125 - c_crc[2] = crc >> 16; 126 - c_crc[3] = crc >> 24; 127 - 128 - for (k = 0; k < 4; k++) { 129 - i = (i + 1) & 0xff; 130 - j = (j + s[i]) & 0xff; 131 - swap(i, j); 132 - if ((c_crc[k] ^ s[(s[i] + s[j]) & 0xff]) != icv[k]) 133 - return -(4 | (k << 4)); /* ICV mismatch */ 134 - } 135 - 136 - return 0; 137 - } 138 - 139 - /* encrypts in-place. */ 140 - int wep_encrypt(struct wlandevice *wlandev, u8 *buf, 141 - u8 *dst, u32 len, int keynum, u8 *iv, u8 *icv) 142 - { 143 - u32 i, j, k, crc, keylen; 144 - u8 s[256], key[64]; 145 - 146 - /* no point in WEPping an empty frame */ 147 - if (len <= 0) 148 - return -1; 149 - 150 - /* we need to have a real key.. */ 151 - if (keynum >= NUM_WEPKEYS) 152 - return -2; 153 - keylen = wlandev->wep_keylens[keynum]; 154 - if (keylen <= 0) 155 - return -3; 156 - 157 - /* use a random IV. And skip known weak ones. */ 158 - get_random_bytes(iv, 3); 159 - while ((iv[1] == 0xff) && (iv[0] >= 3) && (iv[0] < keylen)) 160 - get_random_bytes(iv, 3); 161 - 162 - iv[3] = (keynum & 0x03) << 6; 163 - 164 - key[0] = iv[0]; 165 - key[1] = iv[1]; 166 - key[2] = iv[2]; 167 - 168 - /* copy the rest of the key over from the designated key */ 169 - memcpy(key + 3, wlandev->wep_keys[keynum], keylen); 170 - 171 - keylen += 3; /* add in IV bytes */ 172 - 173 - /* set up the RC4 state */ 174 - for (i = 0; i < 256; i++) 175 - s[i] = i; 176 - j = 0; 177 - for (i = 0; i < 256; i++) { 178 - j = (j + s[i] + key[i % keylen]) & 0xff; 179 - swap(i, j); 180 - } 181 - 182 - /* Update CRC32 then apply RC4 to the data */ 183 - i = 0; 184 - j = 0; 185 - for (k = 0; k < len; k++) { 186 - i = (i + 1) & 0xff; 187 - j = (j + s[i]) & 0xff; 188 - swap(i, j); 189 - dst[k] = buf[k] ^ s[(s[i] + s[j]) & 0xff]; 190 - } 191 - crc = ~crc32_le(~0, buf, len); 192 - 193 - /* now let's encrypt the crc */ 194 - icv[0] = crc; 195 - icv[1] = crc >> 8; 196 - icv[2] = crc >> 16; 197 - icv[3] = crc >> 24; 198 - 199 - for (k = 0; k < 4; k++) { 200 - i = (i + 1) & 0xff; 201 - j = (j + s[i]) & 0xff; 202 - swap(i, j); 203 - icv[k] ^= s[(s[i] + s[j]) & 0xff]; 204 - } 205 - 206 - return 0; 207 - }
-1213
drivers/staging/wlan-ng/prism2fw.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* from src/prism2/download/prism2dl.c 3 - * 4 - * utility for downloading prism2 images moved into kernelspace 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - */ 27 - 28 - /*================================================================*/ 29 - /* System Includes */ 30 - #include <linux/ihex.h> 31 - #include <linux/slab.h> 32 - 33 - /*================================================================*/ 34 - /* Local Constants */ 35 - 36 - #define PRISM2_USB_FWFILE "prism2_ru.fw" 37 - MODULE_FIRMWARE(PRISM2_USB_FWFILE); 38 - 39 - #define S3DATA_MAX 5000 40 - #define S3PLUG_MAX 200 41 - #define S3CRC_MAX 200 42 - #define S3INFO_MAX 50 43 - 44 - #define S3ADDR_PLUG (0xff000000UL) 45 - #define S3ADDR_CRC (0xff100000UL) 46 - #define S3ADDR_INFO (0xff200000UL) 47 - #define S3ADDR_START (0xff400000UL) 48 - 49 - #define CHUNKS_MAX 100 50 - 51 - #define WRITESIZE_MAX 4096 52 - 53 - /*================================================================*/ 54 - /* Local Types */ 55 - 56 - struct s3datarec { 57 - u32 len; 58 - u32 addr; 59 - u8 checksum; 60 - u8 *data; 61 - }; 62 - 63 - struct s3plugrec { 64 - u32 itemcode; 65 - u32 addr; 66 - u32 len; 67 - }; 68 - 69 - struct s3crcrec { 70 - u32 addr; 71 - u32 len; 72 - unsigned int dowrite; 73 - }; 74 - 75 - struct s3inforec { 76 - u16 len; 77 - u16 type; 78 - union { 79 - struct hfa384x_compident version; 80 - struct hfa384x_caplevel compat; 81 - u16 buildseq; 82 - struct hfa384x_compident platform; 83 - } info; 84 - }; 85 - 86 - struct pda { 87 - u8 buf[HFA384x_PDA_LEN_MAX]; 88 - struct hfa384x_pdrec *rec[HFA384x_PDA_RECS_MAX]; 89 - unsigned int nrec; 90 - }; 91 - 92 - struct imgchunk { 93 - u32 addr; /* start address */ 94 - u32 len; /* in bytes */ 95 - u16 crc; /* CRC value (if it falls at a chunk boundary) */ 96 - u8 *data; 97 - }; 98 - 99 - /*================================================================*/ 100 - /* Local Static Definitions */ 101 - 102 - /*----------------------------------------------------------------*/ 103 - /* s-record image processing */ 104 - 105 - /* Data records */ 106 - static unsigned int ns3data; 107 - static struct s3datarec *s3data; 108 - 109 - /* Plug records */ 110 - static unsigned int ns3plug; 111 - static struct s3plugrec s3plug[S3PLUG_MAX]; 112 - 113 - /* CRC records */ 114 - static unsigned int ns3crc; 115 - static struct s3crcrec s3crc[S3CRC_MAX]; 116 - 117 - /* Info records */ 118 - static unsigned int ns3info; 119 - static struct s3inforec s3info[S3INFO_MAX]; 120 - 121 - /* S7 record (there _better_ be only one) */ 122 - static u32 startaddr; 123 - 124 - /* Load image chunks */ 125 - static unsigned int nfchunks; 126 - static struct imgchunk fchunk[CHUNKS_MAX]; 127 - 128 - /* Note that for the following pdrec_t arrays, the len and code */ 129 - /* fields are stored in HOST byte order. The mkpdrlist() function */ 130 - /* does the conversion. */ 131 - /*----------------------------------------------------------------*/ 132 - /* PDA, built from [card|newfile]+[addfile1+addfile2...] */ 133 - 134 - static struct pda pda; 135 - static struct hfa384x_compident nicid; 136 - static struct hfa384x_caplevel rfid; 137 - static struct hfa384x_caplevel macid; 138 - static struct hfa384x_caplevel priid; 139 - 140 - /*================================================================*/ 141 - /* Local Function Declarations */ 142 - 143 - static int prism2_fwapply(const struct ihex_binrec *rfptr, 144 - struct wlandevice *wlandev); 145 - 146 - static int read_fwfile(const struct ihex_binrec *rfptr); 147 - 148 - static int mkimage(struct imgchunk *clist, unsigned int *ccnt); 149 - 150 - static int read_cardpda(struct pda *pda, struct wlandevice *wlandev); 151 - 152 - static int mkpdrlist(struct pda *pda); 153 - 154 - static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks, 155 - struct s3plugrec *s3plug, unsigned int ns3plug, 156 - struct pda *pda); 157 - 158 - static int crcimage(struct imgchunk *fchunk, unsigned int nfchunks, 159 - struct s3crcrec *s3crc, unsigned int ns3crc); 160 - 161 - static int writeimage(struct wlandevice *wlandev, struct imgchunk *fchunk, 162 - unsigned int nfchunks); 163 - 164 - static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks); 165 - 166 - static void free_srecs(void); 167 - 168 - static int validate_identity(void); 169 - 170 - /*================================================================*/ 171 - /* Function Definitions */ 172 - 173 - /*---------------------------------------------------------------- 174 - * prism2_fwtry 175 - * 176 - * Try and get firmware into memory 177 - * 178 - * Arguments: 179 - * udev usb device structure 180 - * wlandev wlan device structure 181 - * 182 - * Returns: 183 - * 0 - success 184 - * ~0 - failure 185 - *---------------------------------------------------------------- 186 - */ 187 - static int prism2_fwtry(struct usb_device *udev, struct wlandevice *wlandev) 188 - { 189 - const struct firmware *fw_entry = NULL; 190 - 191 - netdev_info(wlandev->netdev, "prism2_usb: Checking for firmware %s\n", 192 - PRISM2_USB_FWFILE); 193 - if (request_ihex_firmware(&fw_entry, 194 - PRISM2_USB_FWFILE, &udev->dev) != 0) { 195 - netdev_info(wlandev->netdev, 196 - "prism2_usb: Firmware not available, but not essential\n"); 197 - netdev_info(wlandev->netdev, 198 - "prism2_usb: can continue to use card anyway.\n"); 199 - return 1; 200 - } 201 - 202 - netdev_info(wlandev->netdev, 203 - "prism2_usb: %s will be processed, size %zu\n", 204 - PRISM2_USB_FWFILE, fw_entry->size); 205 - prism2_fwapply((const struct ihex_binrec *)fw_entry->data, wlandev); 206 - 207 - release_firmware(fw_entry); 208 - return 0; 209 - } 210 - 211 - /*---------------------------------------------------------------- 212 - * prism2_fwapply 213 - * 214 - * Apply the firmware loaded into memory 215 - * 216 - * Arguments: 217 - * rfptr firmware image in kernel memory 218 - * wlandev device 219 - * 220 - * Returns: 221 - * 0 - success 222 - * ~0 - failure 223 - *---------------------------------------------------------------- 224 - */ 225 - static int prism2_fwapply(const struct ihex_binrec *rfptr, 226 - struct wlandevice *wlandev) 227 - { 228 - signed int result = 0; 229 - struct p80211msg_dot11req_mibget getmsg; 230 - struct p80211itemd *item; 231 - u32 *data; 232 - 233 - /* Initialize the data structures */ 234 - ns3data = 0; 235 - s3data = kcalloc(S3DATA_MAX, sizeof(*s3data), GFP_KERNEL); 236 - if (!s3data) { 237 - result = -ENOMEM; 238 - goto out; 239 - } 240 - 241 - ns3plug = 0; 242 - memset(s3plug, 0, sizeof(s3plug)); 243 - ns3crc = 0; 244 - memset(s3crc, 0, sizeof(s3crc)); 245 - ns3info = 0; 246 - memset(s3info, 0, sizeof(s3info)); 247 - startaddr = 0; 248 - 249 - nfchunks = 0; 250 - memset(fchunk, 0, sizeof(fchunk)); 251 - memset(&nicid, 0, sizeof(nicid)); 252 - memset(&rfid, 0, sizeof(rfid)); 253 - memset(&macid, 0, sizeof(macid)); 254 - memset(&priid, 0, sizeof(priid)); 255 - 256 - /* clear the pda and add an initial END record */ 257 - memset(&pda, 0, sizeof(pda)); 258 - pda.rec[0] = (struct hfa384x_pdrec *)pda.buf; 259 - pda.rec[0]->len = cpu_to_le16(2); /* len in words */ 260 - pda.rec[0]->code = cpu_to_le16(HFA384x_PDR_END_OF_PDA); 261 - pda.nrec = 1; 262 - 263 - /*-----------------------------------------------------*/ 264 - /* Put card into fwload state */ 265 - prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload); 266 - 267 - /* Build the PDA we're going to use. */ 268 - if (read_cardpda(&pda, wlandev)) { 269 - netdev_err(wlandev->netdev, "load_cardpda failed, exiting.\n"); 270 - result = 1; 271 - goto out; 272 - } 273 - 274 - /* read the card's PRI-SUP */ 275 - memset(&getmsg, 0, sizeof(getmsg)); 276 - getmsg.msgcode = DIDMSG_DOT11REQ_MIBGET; 277 - getmsg.msglen = sizeof(getmsg); 278 - strscpy(getmsg.devname, wlandev->name, sizeof(getmsg.devname)); 279 - 280 - getmsg.mibattribute.did = DIDMSG_DOT11REQ_MIBGET_MIBATTRIBUTE; 281 - getmsg.mibattribute.status = P80211ENUM_msgitem_status_data_ok; 282 - getmsg.resultcode.did = DIDMSG_DOT11REQ_MIBGET_RESULTCODE; 283 - getmsg.resultcode.status = P80211ENUM_msgitem_status_no_value; 284 - 285 - item = (struct p80211itemd *)getmsg.mibattribute.data; 286 - item->did = DIDMIB_P2_NIC_PRISUPRANGE; 287 - item->status = P80211ENUM_msgitem_status_no_value; 288 - 289 - data = (u32 *)item->data; 290 - 291 - /* DIDmsg_dot11req_mibget */ 292 - prism2mgmt_mibset_mibget(wlandev, &getmsg); 293 - if (getmsg.resultcode.data != P80211ENUM_resultcode_success) 294 - netdev_err(wlandev->netdev, "Couldn't fetch PRI-SUP info\n"); 295 - 296 - /* Already in host order */ 297 - priid.role = *data++; 298 - priid.id = *data++; 299 - priid.variant = *data++; 300 - priid.bottom = *data++; 301 - priid.top = *data++; 302 - 303 - /* Read the S3 file */ 304 - result = read_fwfile(rfptr); 305 - if (result) { 306 - netdev_err(wlandev->netdev, 307 - "Failed to read the data exiting.\n"); 308 - goto out; 309 - } 310 - 311 - result = validate_identity(); 312 - if (result) { 313 - netdev_err(wlandev->netdev, "Incompatible firmware image.\n"); 314 - goto out; 315 - } 316 - 317 - if (startaddr == 0x00000000) { 318 - netdev_err(wlandev->netdev, 319 - "Can't RAM download a Flash image!\n"); 320 - result = 1; 321 - goto out; 322 - } 323 - 324 - /* Make the image chunks */ 325 - result = mkimage(fchunk, &nfchunks); 326 - if (result) { 327 - netdev_err(wlandev->netdev, "Failed to make image chunk.\n"); 328 - goto free_chunks; 329 - } 330 - 331 - /* Do any plugging */ 332 - result = plugimage(fchunk, nfchunks, s3plug, ns3plug, &pda); 333 - if (result) { 334 - netdev_err(wlandev->netdev, "Failed to plug data.\n"); 335 - goto free_chunks; 336 - } 337 - 338 - /* Insert any CRCs */ 339 - result = crcimage(fchunk, nfchunks, s3crc, ns3crc); 340 - if (result) { 341 - netdev_err(wlandev->netdev, "Failed to insert all CRCs\n"); 342 - goto free_chunks; 343 - } 344 - 345 - /* Write the image */ 346 - result = writeimage(wlandev, fchunk, nfchunks); 347 - if (result) { 348 - netdev_err(wlandev->netdev, "Failed to ramwrite image data.\n"); 349 - goto free_chunks; 350 - } 351 - 352 - netdev_info(wlandev->netdev, "prism2_usb: firmware loading finished.\n"); 353 - 354 - free_chunks: 355 - /* clear any allocated memory */ 356 - free_chunks(fchunk, &nfchunks); 357 - free_srecs(); 358 - 359 - out: 360 - return result; 361 - } 362 - 363 - /*---------------------------------------------------------------- 364 - * crcimage 365 - * 366 - * Adds a CRC16 in the two bytes prior to each block identified by 367 - * an S3 CRC record. Currently, we don't actually do a CRC we just 368 - * insert the value 0xC0DE in hfa384x order. 369 - * 370 - * Arguments: 371 - * fchunk Array of image chunks 372 - * nfchunks Number of image chunks 373 - * s3crc Array of crc records 374 - * ns3crc Number of crc records 375 - * 376 - * Returns: 377 - * 0 success 378 - * ~0 failure 379 - *---------------------------------------------------------------- 380 - */ 381 - static int crcimage(struct imgchunk *fchunk, unsigned int nfchunks, 382 - struct s3crcrec *s3crc, unsigned int ns3crc) 383 - { 384 - int result = 0; 385 - int i; 386 - int c; 387 - u32 crcstart; 388 - u32 cstart = 0; 389 - u32 cend; 390 - u8 *dest; 391 - u32 chunkoff; 392 - 393 - for (i = 0; i < ns3crc; i++) { 394 - if (!s3crc[i].dowrite) 395 - continue; 396 - crcstart = s3crc[i].addr; 397 - /* Find chunk */ 398 - for (c = 0; c < nfchunks; c++) { 399 - cstart = fchunk[c].addr; 400 - cend = fchunk[c].addr + fchunk[c].len; 401 - /* the line below does an address & len match search */ 402 - /* unfortunately, I've found that the len fields of */ 403 - /* some crc records don't match with the length of */ 404 - /* the actual data, so we're not checking right now */ 405 - /* if (crcstart-2 >= cstart && crcend <= cend) break; */ 406 - 407 - /* note the -2 below, it's to make sure the chunk has */ 408 - /* space for the CRC value */ 409 - if (crcstart - 2 >= cstart && crcstart < cend) 410 - break; 411 - } 412 - if (c >= nfchunks) { 413 - pr_err("Failed to find chunk for crcrec[%d], addr=0x%06x len=%d , aborting crc.\n", 414 - i, s3crc[i].addr, s3crc[i].len); 415 - return 1; 416 - } 417 - 418 - /* Insert crc */ 419 - pr_debug("Adding crc @ 0x%06x\n", s3crc[i].addr - 2); 420 - chunkoff = crcstart - cstart - 2; 421 - dest = fchunk[c].data + chunkoff; 422 - *dest = 0xde; 423 - *(dest + 1) = 0xc0; 424 - } 425 - return result; 426 - } 427 - 428 - /*---------------------------------------------------------------- 429 - * free_chunks 430 - * 431 - * Clears the chunklist data structures in preparation for a new file. 432 - * 433 - * Arguments: 434 - * none 435 - * 436 - * Returns: 437 - * nothing 438 - *---------------------------------------------------------------- 439 - */ 440 - static void free_chunks(struct imgchunk *fchunk, unsigned int *nfchunks) 441 - { 442 - int i; 443 - 444 - for (i = 0; i < *nfchunks; i++) 445 - kfree(fchunk[i].data); 446 - 447 - *nfchunks = 0; 448 - memset(fchunk, 0, sizeof(*fchunk)); 449 - } 450 - 451 - /*---------------------------------------------------------------- 452 - * free_srecs 453 - * 454 - * Clears the srec data structures in preparation for a new file. 455 - * 456 - * Arguments: 457 - * none 458 - * 459 - * Returns: 460 - * nothing 461 - *---------------------------------------------------------------- 462 - */ 463 - static void free_srecs(void) 464 - { 465 - ns3data = 0; 466 - kfree(s3data); 467 - ns3plug = 0; 468 - memset(s3plug, 0, sizeof(s3plug)); 469 - ns3crc = 0; 470 - memset(s3crc, 0, sizeof(s3crc)); 471 - ns3info = 0; 472 - memset(s3info, 0, sizeof(s3info)); 473 - startaddr = 0; 474 - } 475 - 476 - /*---------------------------------------------------------------- 477 - * mkimage 478 - * 479 - * Scans the currently loaded set of S records for data residing 480 - * in contiguous memory regions. Each contiguous region is then 481 - * made into a 'chunk'. This function assumes that we're building 482 - * a new chunk list. Assumes the s3data items are in sorted order. 483 - * 484 - * Arguments: none 485 - * 486 - * Returns: 487 - * 0 - success 488 - * ~0 - failure (probably an errno) 489 - *---------------------------------------------------------------- 490 - */ 491 - static int mkimage(struct imgchunk *clist, unsigned int *ccnt) 492 - { 493 - int result = 0; 494 - int i; 495 - int j; 496 - int currchunk = 0; 497 - u32 nextaddr = 0; 498 - u32 s3start; 499 - u32 s3end; 500 - u32 cstart = 0; 501 - u32 cend; 502 - u32 coffset; 503 - 504 - /* There may already be data in the chunklist */ 505 - *ccnt = 0; 506 - 507 - /* Establish the location and size of each chunk */ 508 - for (i = 0; i < ns3data; i++) { 509 - if (s3data[i].addr == nextaddr) { 510 - /* existing chunk, grow it */ 511 - clist[currchunk].len += s3data[i].len; 512 - nextaddr += s3data[i].len; 513 - } else { 514 - /* New chunk */ 515 - (*ccnt)++; 516 - currchunk = *ccnt - 1; 517 - clist[currchunk].addr = s3data[i].addr; 518 - clist[currchunk].len = s3data[i].len; 519 - nextaddr = s3data[i].addr + s3data[i].len; 520 - /* Expand the chunk if there is a CRC record at */ 521 - /* their beginning bound */ 522 - for (j = 0; j < ns3crc; j++) { 523 - if (s3crc[j].dowrite && 524 - s3crc[j].addr == clist[currchunk].addr) { 525 - clist[currchunk].addr -= 2; 526 - clist[currchunk].len += 2; 527 - } 528 - } 529 - } 530 - } 531 - 532 - /* We're currently assuming there aren't any overlapping chunks */ 533 - /* if this proves false, we'll need to add code to coalesce. */ 534 - 535 - /* Allocate buffer space for chunks */ 536 - for (i = 0; i < *ccnt; i++) { 537 - clist[i].data = kzalloc(clist[i].len, GFP_KERNEL); 538 - if (!clist[i].data) 539 - return 1; 540 - 541 - pr_debug("chunk[%d]: addr=0x%06x len=%d\n", 542 - i, clist[i].addr, clist[i].len); 543 - } 544 - 545 - /* Copy srec data to chunks */ 546 - for (i = 0; i < ns3data; i++) { 547 - s3start = s3data[i].addr; 548 - s3end = s3start + s3data[i].len - 1; 549 - for (j = 0; j < *ccnt; j++) { 550 - cstart = clist[j].addr; 551 - cend = cstart + clist[j].len - 1; 552 - if (s3start >= cstart && s3end <= cend) 553 - break; 554 - } 555 - if (((unsigned int)j) >= (*ccnt)) { 556 - pr_err("s3rec(a=0x%06x,l=%d), no chunk match, exiting.\n", 557 - s3start, s3data[i].len); 558 - return 1; 559 - } 560 - coffset = s3start - cstart; 561 - memcpy(clist[j].data + coffset, s3data[i].data, s3data[i].len); 562 - } 563 - 564 - return result; 565 - } 566 - 567 - /*---------------------------------------------------------------- 568 - * mkpdrlist 569 - * 570 - * Reads a raw PDA and builds an array of pdrec_t structures. 571 - * 572 - * Arguments: 573 - * pda buffer containing raw PDA bytes 574 - * pdrec ptr to an array of pdrec_t's. Will be filled on exit. 575 - * nrec ptr to a variable that will contain the count of PDRs 576 - * 577 - * Returns: 578 - * 0 - success 579 - * ~0 - failure (probably an errno) 580 - *---------------------------------------------------------------- 581 - */ 582 - static int mkpdrlist(struct pda *pda) 583 - { 584 - __le16 *pda16 = (__le16 *)pda->buf; 585 - int curroff; /* in 'words' */ 586 - 587 - pda->nrec = 0; 588 - curroff = 0; 589 - while (curroff < (HFA384x_PDA_LEN_MAX / 2 - 1) && 590 - le16_to_cpu(pda16[curroff + 1]) != HFA384x_PDR_END_OF_PDA) { 591 - pda->rec[pda->nrec] = (struct hfa384x_pdrec *)&pda16[curroff]; 592 - 593 - if (le16_to_cpu(pda->rec[pda->nrec]->code) == 594 - HFA384x_PDR_NICID) { 595 - memcpy(&nicid, &pda->rec[pda->nrec]->data.nicid, 596 - sizeof(nicid)); 597 - le16_to_cpus(&nicid.id); 598 - le16_to_cpus(&nicid.variant); 599 - le16_to_cpus(&nicid.major); 600 - le16_to_cpus(&nicid.minor); 601 - } 602 - if (le16_to_cpu(pda->rec[pda->nrec]->code) == 603 - HFA384x_PDR_MFISUPRANGE) { 604 - memcpy(&rfid, &pda->rec[pda->nrec]->data.mfisuprange, 605 - sizeof(rfid)); 606 - le16_to_cpus(&rfid.id); 607 - le16_to_cpus(&rfid.variant); 608 - le16_to_cpus(&rfid.bottom); 609 - le16_to_cpus(&rfid.top); 610 - } 611 - if (le16_to_cpu(pda->rec[pda->nrec]->code) == 612 - HFA384x_PDR_CFISUPRANGE) { 613 - memcpy(&macid, &pda->rec[pda->nrec]->data.cfisuprange, 614 - sizeof(macid)); 615 - le16_to_cpus(&macid.id); 616 - le16_to_cpus(&macid.variant); 617 - le16_to_cpus(&macid.bottom); 618 - le16_to_cpus(&macid.top); 619 - } 620 - 621 - (pda->nrec)++; 622 - curroff += le16_to_cpu(pda16[curroff]) + 1; 623 - } 624 - if (curroff >= (HFA384x_PDA_LEN_MAX / 2 - 1)) { 625 - pr_err("no end record found or invalid lengths in PDR data, exiting. %x %d\n", 626 - curroff, pda->nrec); 627 - return 1; 628 - } 629 - pda->rec[pda->nrec] = (struct hfa384x_pdrec *)&pda16[curroff]; 630 - (pda->nrec)++; 631 - return 0; 632 - } 633 - 634 - /*---------------------------------------------------------------- 635 - * plugimage 636 - * 637 - * Plugs the given image using the given plug records from the given 638 - * PDA and filename. 639 - * 640 - * Arguments: 641 - * fchunk Array of image chunks 642 - * nfchunks Number of image chunks 643 - * s3plug Array of plug records 644 - * ns3plug Number of plug records 645 - * pda Current pda data 646 - * 647 - * Returns: 648 - * 0 success 649 - * ~0 failure 650 - *---------------------------------------------------------------- 651 - */ 652 - static int plugimage(struct imgchunk *fchunk, unsigned int nfchunks, 653 - struct s3plugrec *s3plug, unsigned int ns3plug, 654 - struct pda *pda) 655 - { 656 - int result = 0; 657 - int i; /* plug index */ 658 - int j; /* index of PDR or -1 if fname plug */ 659 - int c; /* chunk index */ 660 - u32 pstart; 661 - u32 pend; 662 - u32 cstart = 0; 663 - u32 cend; 664 - u32 chunkoff; 665 - u8 *dest; 666 - 667 - /* for each plug record */ 668 - for (i = 0; i < ns3plug; i++) { 669 - pstart = s3plug[i].addr; 670 - pend = s3plug[i].addr + s3plug[i].len; 671 - j = -1; 672 - /* find the matching PDR (or filename) */ 673 - if (s3plug[i].itemcode != 0xffffffffUL) { /* not filename */ 674 - for (j = 0; j < pda->nrec; j++) { 675 - if (s3plug[i].itemcode == 676 - le16_to_cpu(pda->rec[j]->code)) 677 - break; 678 - } 679 - } 680 - if (j >= pda->nrec && j != -1) { /* if no matching PDR, fail */ 681 - pr_warn("warning: Failed to find PDR for plugrec 0x%04x.\n", 682 - s3plug[i].itemcode); 683 - continue; /* and move on to the next PDR */ 684 - 685 - /* MSM: They swear that unless it's the MAC address, 686 - * the serial number, or the TX calibration records, 687 - * then there's reasonable defaults in the f/w 688 - * image. Therefore, missing PDRs in the card 689 - * should only be a warning, not fatal. 690 - * TODO: add fatals for the PDRs mentioned above. 691 - */ 692 - } 693 - 694 - /* Validate plug len against PDR len */ 695 - if (j != -1 && s3plug[i].len < le16_to_cpu(pda->rec[j]->len)) { 696 - pr_err("error: Plug vs. PDR len mismatch for plugrec 0x%04x, abort plugging.\n", 697 - s3plug[i].itemcode); 698 - result = 1; 699 - continue; 700 - } 701 - 702 - /* 703 - * Validate plug address against 704 - * chunk data and identify chunk 705 - */ 706 - for (c = 0; c < nfchunks; c++) { 707 - cstart = fchunk[c].addr; 708 - cend = fchunk[c].addr + fchunk[c].len; 709 - if (pstart >= cstart && pend <= cend) 710 - break; 711 - } 712 - if (c >= nfchunks) { 713 - pr_err("error: Failed to find image chunk for plugrec 0x%04x.\n", 714 - s3plug[i].itemcode); 715 - result = 1; 716 - continue; 717 - } 718 - 719 - /* Plug data */ 720 - chunkoff = pstart - cstart; 721 - dest = fchunk[c].data + chunkoff; 722 - pr_debug("Plugging item 0x%04x @ 0x%06x, len=%d, cnum=%d coff=0x%06x\n", 723 - s3plug[i].itemcode, pstart, s3plug[i].len, 724 - c, chunkoff); 725 - 726 - if (j == -1) { /* plug the filename */ 727 - memset(dest, 0, s3plug[i].len); 728 - strscpy(dest, PRISM2_USB_FWFILE, s3plug[i].len); 729 - } else { /* plug a PDR */ 730 - memcpy(dest, &pda->rec[j]->data, s3plug[i].len); 731 - } 732 - } 733 - return result; 734 - } 735 - 736 - /*---------------------------------------------------------------- 737 - * read_cardpda 738 - * 739 - * Sends the command for the driver to read the pda from the card 740 - * named in the device variable. Upon success, the card pda is 741 - * stored in the "cardpda" variables. Note that the pda structure 742 - * is considered 'well formed' after this function. That means 743 - * that the nrecs is valid, the rec array has been set up, and there's 744 - * a valid PDAEND record in the raw PDA data. 745 - * 746 - * Arguments: 747 - * pda pda structure 748 - * wlandev device 749 - * 750 - * Returns: 751 - * 0 - success 752 - * ~0 - failure (probably an errno) 753 - *---------------------------------------------------------------- 754 - */ 755 - static int read_cardpda(struct pda *pda, struct wlandevice *wlandev) 756 - { 757 - int result = 0; 758 - struct p80211msg_p2req_readpda *msg; 759 - 760 - msg = kzalloc(sizeof(*msg), GFP_KERNEL); 761 - if (!msg) 762 - return -ENOMEM; 763 - 764 - /* set up the msg */ 765 - msg->msgcode = DIDMSG_P2REQ_READPDA; 766 - msg->msglen = sizeof(msg); 767 - strscpy(msg->devname, wlandev->name, sizeof(msg->devname)); 768 - msg->pda.did = DIDMSG_P2REQ_READPDA_PDA; 769 - msg->pda.len = HFA384x_PDA_LEN_MAX; 770 - msg->pda.status = P80211ENUM_msgitem_status_no_value; 771 - msg->resultcode.did = DIDMSG_P2REQ_READPDA_RESULTCODE; 772 - msg->resultcode.len = sizeof(u32); 773 - msg->resultcode.status = P80211ENUM_msgitem_status_no_value; 774 - 775 - if (prism2mgmt_readpda(wlandev, msg) != 0) { 776 - /* prism2mgmt_readpda prints an errno if appropriate */ 777 - result = -1; 778 - } else if (msg->resultcode.data == P80211ENUM_resultcode_success) { 779 - memcpy(pda->buf, msg->pda.data, HFA384x_PDA_LEN_MAX); 780 - result = mkpdrlist(pda); 781 - } else { 782 - /* resultcode must've been something other than success */ 783 - result = -1; 784 - } 785 - 786 - kfree(msg); 787 - return result; 788 - } 789 - 790 - /*---------------------------------------------------------------- 791 - * read_fwfile 792 - * 793 - * Reads the given fw file which should have been compiled from an srec 794 - * file. Each record in the fw file will either be a plain data record, 795 - * a start address record, or other records used for plugging. 796 - * 797 - * Note that data records are expected to be sorted into 798 - * ascending address order in the fw file. 799 - * 800 - * Note also that the start address record, originally an S7 record in 801 - * the srec file, is expected in the fw file to be like a data record but 802 - * with a certain address to make it identifiable. 803 - * 804 - * Here's the SREC format that the fw should have come from: 805 - * S[37]nnaaaaaaaaddd...dddcc 806 - * 807 - * nn - number of bytes starting with the address field 808 - * aaaaaaaa - address in readable (or big endian) format 809 - * dd....dd - 0-245 data bytes (two chars per byte) 810 - * cc - checksum 811 - * 812 - * The S7 record's (there should be only one) address value gets 813 - * converted to an S3 record with address of 0xff400000, with the 814 - * start address being stored as a 4 byte data word. That address is 815 - * the start execution address used for RAM downloads. 816 - * 817 - * The S3 records have a collection of subformats indicated by the 818 - * value of aaaaaaaa: 819 - * 0xff000000 - Plug record, data field format: 820 - * xxxxxxxxaaaaaaaassssssss 821 - * x - PDR code number (little endian) 822 - * a - Address in load image to plug (little endian) 823 - * s - Length of plug data area (little endian) 824 - * 825 - * 0xff100000 - CRC16 generation record, data field format: 826 - * aaaaaaaassssssssbbbbbbbb 827 - * a - Start address for CRC calculation (little endian) 828 - * s - Length of data to calculate over (little endian) 829 - * b - Boolean, true=write crc, false=don't write 830 - * 831 - * 0xff200000 - Info record, data field format: 832 - * ssssttttdd..dd 833 - * s - Size in words (little endian) 834 - * t - Info type (little endian), see #defines and 835 - * struct s3inforec for details about types. 836 - * d - (s - 1) little endian words giving the contents of 837 - * the given info type. 838 - * 839 - * 0xff400000 - Start address record, data field format: 840 - * aaaaaaaa 841 - * a - Address in load image to plug (little endian) 842 - * 843 - * Arguments: 844 - * record firmware image (ihex record structure) in kernel memory 845 - * 846 - * Returns: 847 - * 0 - success 848 - * ~0 - failure (probably an errno) 849 - *---------------------------------------------------------------- 850 - */ 851 - static int read_fwfile(const struct ihex_binrec *record) 852 - { 853 - int i; 854 - int rcnt = 0; 855 - u16 *tmpinfo; 856 - u16 *ptr16; 857 - u32 *ptr32, len, addr; 858 - 859 - pr_debug("Reading fw file ...\n"); 860 - 861 - while (record) { 862 - rcnt++; 863 - 864 - len = be16_to_cpu(record->len); 865 - addr = be32_to_cpu(record->addr); 866 - 867 - /* Point into data for different word lengths */ 868 - ptr32 = (u32 *)record->data; 869 - ptr16 = (u16 *)record->data; 870 - 871 - /* parse what was an S3 srec and put it in the right array */ 872 - switch (addr) { 873 - case S3ADDR_START: 874 - startaddr = *ptr32; 875 - pr_debug(" S7 start addr, record=%d addr=0x%08x\n", 876 - rcnt, 877 - startaddr); 878 - break; 879 - case S3ADDR_PLUG: 880 - s3plug[ns3plug].itemcode = *ptr32; 881 - s3plug[ns3plug].addr = *(ptr32 + 1); 882 - s3plug[ns3plug].len = *(ptr32 + 2); 883 - 884 - pr_debug(" S3 plugrec, record=%d itemcode=0x%08x addr=0x%08x len=%d\n", 885 - rcnt, 886 - s3plug[ns3plug].itemcode, 887 - s3plug[ns3plug].addr, 888 - s3plug[ns3plug].len); 889 - 890 - ns3plug++; 891 - if (ns3plug == S3PLUG_MAX) { 892 - pr_err("S3 plugrec limit reached - aborting\n"); 893 - return 1; 894 - } 895 - break; 896 - case S3ADDR_CRC: 897 - s3crc[ns3crc].addr = *ptr32; 898 - s3crc[ns3crc].len = *(ptr32 + 1); 899 - s3crc[ns3crc].dowrite = *(ptr32 + 2); 900 - 901 - pr_debug(" S3 crcrec, record=%d addr=0x%08x len=%d write=0x%08x\n", 902 - rcnt, 903 - s3crc[ns3crc].addr, 904 - s3crc[ns3crc].len, 905 - s3crc[ns3crc].dowrite); 906 - ns3crc++; 907 - if (ns3crc == S3CRC_MAX) { 908 - pr_err("S3 crcrec limit reached - aborting\n"); 909 - return 1; 910 - } 911 - break; 912 - case S3ADDR_INFO: 913 - s3info[ns3info].len = *ptr16; 914 - s3info[ns3info].type = *(ptr16 + 1); 915 - 916 - pr_debug(" S3 inforec, record=%d len=0x%04x type=0x%04x\n", 917 - rcnt, 918 - s3info[ns3info].len, 919 - s3info[ns3info].type); 920 - if (((s3info[ns3info].len - 1) * sizeof(u16)) > 921 - sizeof(s3info[ns3info].info)) { 922 - pr_err("S3 inforec length too long - aborting\n"); 923 - return 1; 924 - } 925 - 926 - tmpinfo = (u16 *)&s3info[ns3info].info.version; 927 - pr_debug(" info="); 928 - for (i = 0; i < s3info[ns3info].len - 1; i++) { 929 - tmpinfo[i] = *(ptr16 + 2 + i); 930 - pr_debug("%04x ", tmpinfo[i]); 931 - } 932 - pr_debug("\n"); 933 - 934 - ns3info++; 935 - if (ns3info == S3INFO_MAX) { 936 - pr_err("S3 inforec limit reached - aborting\n"); 937 - return 1; 938 - } 939 - break; 940 - default: /* Data record */ 941 - s3data[ns3data].addr = addr; 942 - s3data[ns3data].len = len; 943 - s3data[ns3data].data = (uint8_t *)record->data; 944 - ns3data++; 945 - if (ns3data == S3DATA_MAX) { 946 - pr_err("S3 datarec limit reached - aborting\n"); 947 - return 1; 948 - } 949 - break; 950 - } 951 - record = ihex_next_binrec(record); 952 - } 953 - return 0; 954 - } 955 - 956 - /*---------------------------------------------------------------- 957 - * writeimage 958 - * 959 - * Takes the chunks, builds p80211 messages and sends them down 960 - * to the driver for writing to the card. 961 - * 962 - * Arguments: 963 - * wlandev device 964 - * fchunk Array of image chunks 965 - * nfchunks Number of image chunks 966 - * 967 - * Returns: 968 - * 0 success 969 - * ~0 failure 970 - *---------------------------------------------------------------- 971 - */ 972 - static int writeimage(struct wlandevice *wlandev, struct imgchunk *fchunk, 973 - unsigned int nfchunks) 974 - { 975 - int result = 0; 976 - struct p80211msg_p2req_ramdl_state *rstmsg; 977 - struct p80211msg_p2req_ramdl_write *rwrmsg; 978 - u32 resultcode; 979 - int i; 980 - int j; 981 - unsigned int nwrites; 982 - u32 curroff; 983 - u32 currlen; 984 - u32 currdaddr; 985 - 986 - rstmsg = kzalloc(sizeof(*rstmsg), GFP_KERNEL); 987 - rwrmsg = kzalloc(sizeof(*rwrmsg), GFP_KERNEL); 988 - if (!rstmsg || !rwrmsg) { 989 - netdev_err(wlandev->netdev, 990 - "%s: no memory for firmware download, aborting download\n", 991 - __func__); 992 - result = -ENOMEM; 993 - goto free_result; 994 - } 995 - 996 - /* Initialize the messages */ 997 - strscpy(rstmsg->devname, wlandev->name, sizeof(rstmsg->devname)); 998 - rstmsg->msgcode = DIDMSG_P2REQ_RAMDL_STATE; 999 - rstmsg->msglen = sizeof(*rstmsg); 1000 - rstmsg->enable.did = DIDMSG_P2REQ_RAMDL_STATE_ENABLE; 1001 - rstmsg->exeaddr.did = DIDMSG_P2REQ_RAMDL_STATE_EXEADDR; 1002 - rstmsg->resultcode.did = DIDMSG_P2REQ_RAMDL_STATE_RESULTCODE; 1003 - rstmsg->enable.status = P80211ENUM_msgitem_status_data_ok; 1004 - rstmsg->exeaddr.status = P80211ENUM_msgitem_status_data_ok; 1005 - rstmsg->resultcode.status = P80211ENUM_msgitem_status_no_value; 1006 - rstmsg->enable.len = sizeof(u32); 1007 - rstmsg->exeaddr.len = sizeof(u32); 1008 - rstmsg->resultcode.len = sizeof(u32); 1009 - 1010 - strscpy(rwrmsg->devname, wlandev->name, sizeof(rwrmsg->devname)); 1011 - rwrmsg->msgcode = DIDMSG_P2REQ_RAMDL_WRITE; 1012 - rwrmsg->msglen = sizeof(*rwrmsg); 1013 - rwrmsg->addr.did = DIDMSG_P2REQ_RAMDL_WRITE_ADDR; 1014 - rwrmsg->len.did = DIDMSG_P2REQ_RAMDL_WRITE_LEN; 1015 - rwrmsg->data.did = DIDMSG_P2REQ_RAMDL_WRITE_DATA; 1016 - rwrmsg->resultcode.did = DIDMSG_P2REQ_RAMDL_WRITE_RESULTCODE; 1017 - rwrmsg->addr.status = P80211ENUM_msgitem_status_data_ok; 1018 - rwrmsg->len.status = P80211ENUM_msgitem_status_data_ok; 1019 - rwrmsg->data.status = P80211ENUM_msgitem_status_data_ok; 1020 - rwrmsg->resultcode.status = P80211ENUM_msgitem_status_no_value; 1021 - rwrmsg->addr.len = sizeof(u32); 1022 - rwrmsg->len.len = sizeof(u32); 1023 - rwrmsg->data.len = WRITESIZE_MAX; 1024 - rwrmsg->resultcode.len = sizeof(u32); 1025 - 1026 - /* Send xxx_state(enable) */ 1027 - pr_debug("Sending dl_state(enable) message.\n"); 1028 - rstmsg->enable.data = P80211ENUM_truth_true; 1029 - rstmsg->exeaddr.data = startaddr; 1030 - 1031 - result = prism2mgmt_ramdl_state(wlandev, rstmsg); 1032 - if (result) { 1033 - netdev_err(wlandev->netdev, 1034 - "%s state enable failed w/ result=%d, aborting download\n", 1035 - __func__, result); 1036 - goto free_result; 1037 - } 1038 - resultcode = rstmsg->resultcode.data; 1039 - if (resultcode != P80211ENUM_resultcode_success) { 1040 - netdev_err(wlandev->netdev, 1041 - "%s()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n", 1042 - __func__, resultcode); 1043 - result = 1; 1044 - goto free_result; 1045 - } 1046 - 1047 - /* Now, loop through the data chunks and send WRITESIZE_MAX data */ 1048 - for (i = 0; i < nfchunks; i++) { 1049 - nwrites = fchunk[i].len / WRITESIZE_MAX; 1050 - nwrites += (fchunk[i].len % WRITESIZE_MAX) ? 1 : 0; 1051 - curroff = 0; 1052 - for (j = 0; j < nwrites; j++) { 1053 - /* TODO Move this to a separate function */ 1054 - int lenleft = fchunk[i].len - (WRITESIZE_MAX * j); 1055 - 1056 - if (fchunk[i].len > WRITESIZE_MAX) 1057 - currlen = WRITESIZE_MAX; 1058 - else 1059 - currlen = lenleft; 1060 - curroff = j * WRITESIZE_MAX; 1061 - currdaddr = fchunk[i].addr + curroff; 1062 - /* Setup the message */ 1063 - rwrmsg->addr.data = currdaddr; 1064 - rwrmsg->len.data = currlen; 1065 - memcpy(rwrmsg->data.data, 1066 - fchunk[i].data + curroff, currlen); 1067 - 1068 - /* Send flashdl_write(pda) */ 1069 - pr_debug 1070 - ("Sending xxxdl_write message addr=%06x len=%d.\n", 1071 - currdaddr, currlen); 1072 - 1073 - result = prism2mgmt_ramdl_write(wlandev, rwrmsg); 1074 - 1075 - /* Check the results */ 1076 - if (result) { 1077 - netdev_err(wlandev->netdev, 1078 - "%s chunk write failed w/ result=%d, aborting download\n", 1079 - __func__, result); 1080 - goto free_result; 1081 - } 1082 - resultcode = rstmsg->resultcode.data; 1083 - if (resultcode != P80211ENUM_resultcode_success) { 1084 - pr_err("%s()->xxxdl_write msg indicates failure, w/ resultcode=%d, aborting download.\n", 1085 - __func__, resultcode); 1086 - result = 1; 1087 - goto free_result; 1088 - } 1089 - } 1090 - } 1091 - 1092 - /* Send xxx_state(disable) */ 1093 - pr_debug("Sending dl_state(disable) message.\n"); 1094 - rstmsg->enable.data = P80211ENUM_truth_false; 1095 - rstmsg->exeaddr.data = 0; 1096 - 1097 - result = prism2mgmt_ramdl_state(wlandev, rstmsg); 1098 - if (result) { 1099 - netdev_err(wlandev->netdev, 1100 - "%s state disable failed w/ result=%d, aborting download\n", 1101 - __func__, result); 1102 - goto free_result; 1103 - } 1104 - resultcode = rstmsg->resultcode.data; 1105 - if (resultcode != P80211ENUM_resultcode_success) { 1106 - netdev_err(wlandev->netdev, 1107 - "%s()->xxxdl_state msg indicates failure, w/ resultcode=%d, aborting download.\n", 1108 - __func__, resultcode); 1109 - result = 1; 1110 - goto free_result; 1111 - } 1112 - 1113 - free_result: 1114 - kfree(rstmsg); 1115 - kfree(rwrmsg); 1116 - return result; 1117 - } 1118 - 1119 - static int validate_identity(void) 1120 - { 1121 - int i; 1122 - int result = 1; 1123 - int trump = 0; 1124 - 1125 - pr_debug("NIC ID: %#x v%d.%d.%d\n", 1126 - nicid.id, nicid.major, nicid.minor, nicid.variant); 1127 - pr_debug("MFI ID: %#x v%d %d->%d\n", 1128 - rfid.id, rfid.variant, rfid.bottom, rfid.top); 1129 - pr_debug("CFI ID: %#x v%d %d->%d\n", 1130 - macid.id, macid.variant, macid.bottom, macid.top); 1131 - pr_debug("PRI ID: %#x v%d %d->%d\n", 1132 - priid.id, priid.variant, priid.bottom, priid.top); 1133 - 1134 - for (i = 0; i < ns3info; i++) { 1135 - switch (s3info[i].type) { 1136 - case 1: 1137 - pr_debug("Version: ID %#x %d.%d.%d\n", 1138 - s3info[i].info.version.id, 1139 - s3info[i].info.version.major, 1140 - s3info[i].info.version.minor, 1141 - s3info[i].info.version.variant); 1142 - break; 1143 - case 2: 1144 - pr_debug("Compat: Role %#x Id %#x v%d %d->%d\n", 1145 - s3info[i].info.compat.role, 1146 - s3info[i].info.compat.id, 1147 - s3info[i].info.compat.variant, 1148 - s3info[i].info.compat.bottom, 1149 - s3info[i].info.compat.top); 1150 - 1151 - /* MAC compat range */ 1152 - if ((s3info[i].info.compat.role == 1) && 1153 - (s3info[i].info.compat.id == 2)) { 1154 - if (s3info[i].info.compat.variant != 1155 - macid.variant) { 1156 - result = 2; 1157 - } 1158 - } 1159 - 1160 - /* PRI compat range */ 1161 - if ((s3info[i].info.compat.role == 1) && 1162 - (s3info[i].info.compat.id == 3)) { 1163 - if ((s3info[i].info.compat.bottom > 1164 - priid.top) || 1165 - (s3info[i].info.compat.top < 1166 - priid.bottom)) { 1167 - result = 3; 1168 - } 1169 - } 1170 - /* SEC compat range */ 1171 - if ((s3info[i].info.compat.role == 1) && 1172 - (s3info[i].info.compat.id == 4)) { 1173 - /* FIXME: isn't something missing here? */ 1174 - } 1175 - 1176 - break; 1177 - case 3: 1178 - pr_debug("Seq: %#x\n", s3info[i].info.buildseq); 1179 - 1180 - break; 1181 - case 4: 1182 - pr_debug("Platform: ID %#x %d.%d.%d\n", 1183 - s3info[i].info.version.id, 1184 - s3info[i].info.version.major, 1185 - s3info[i].info.version.minor, 1186 - s3info[i].info.version.variant); 1187 - 1188 - if (nicid.id != s3info[i].info.version.id) 1189 - continue; 1190 - if (nicid.major != s3info[i].info.version.major) 1191 - continue; 1192 - if (nicid.minor != s3info[i].info.version.minor) 1193 - continue; 1194 - if ((nicid.variant != s3info[i].info.version.variant) && 1195 - (nicid.id != 0x8008)) 1196 - continue; 1197 - 1198 - trump = 1; 1199 - break; 1200 - case 0x8001: 1201 - pr_debug("name inforec len %d\n", s3info[i].len); 1202 - 1203 - break; 1204 - default: 1205 - pr_debug("Unknown inforec type %d\n", s3info[i].type); 1206 - } 1207 - } 1208 - /* walk through */ 1209 - 1210 - if (trump && (result != 2)) 1211 - result = 0; 1212 - return result; 1213 - }
-1315
drivers/staging/wlan-ng/prism2mgmt.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Management request handler functions. 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * The functions in this file handle management requests sent from 28 - * user mode. 29 - * 30 - * Most of these functions have two separate blocks of code that are 31 - * conditional on whether this is a station or an AP. This is used 32 - * to separate out the STA and AP responses to these management primitives. 33 - * It's a choice (good, bad, indifferent?) to have the code in the same 34 - * place so it's clear that the same primitive is implemented in both 35 - * cases but has different behavior. 36 - * 37 - * -------------------------------------------------------------------- 38 - */ 39 - 40 - #include <linux/if_arp.h> 41 - #include <linux/module.h> 42 - #include <linux/kernel.h> 43 - #include <linux/wait.h> 44 - #include <linux/sched.h> 45 - #include <linux/types.h> 46 - #include <linux/wireless.h> 47 - #include <linux/netdevice.h> 48 - #include <linux/delay.h> 49 - #include <linux/io.h> 50 - #include <asm/byteorder.h> 51 - #include <linux/random.h> 52 - #include <linux/usb.h> 53 - #include <linux/bitops.h> 54 - 55 - #include "p80211types.h" 56 - #include "p80211hdr.h" 57 - #include "p80211mgmt.h" 58 - #include "p80211conv.h" 59 - #include "p80211msg.h" 60 - #include "p80211netdev.h" 61 - #include "p80211metadef.h" 62 - #include "p80211metastruct.h" 63 - #include "hfa384x.h" 64 - #include "prism2mgmt.h" 65 - 66 - /* Converts 802.11 format rate specifications to prism2 */ 67 - static inline u16 p80211rate_to_p2bit(u32 rate) 68 - { 69 - switch (rate & ~BIT(7)) { 70 - case 2: 71 - return BIT(0); 72 - case 4: 73 - return BIT(1); 74 - case 11: 75 - return BIT(2); 76 - case 22: 77 - return BIT(3); 78 - default: 79 - return 0; 80 - } 81 - } 82 - 83 - /*---------------------------------------------------------------- 84 - * prism2mgmt_scan 85 - * 86 - * Initiate a scan for BSSs. 87 - * 88 - * This function corresponds to MLME-scan.request and part of 89 - * MLME-scan.confirm. As far as I can tell in the standard, there 90 - * are no restrictions on when a scan.request may be issued. We have 91 - * to handle in whatever state the driver/MAC happen to be. 92 - * 93 - * Arguments: 94 - * wlandev wlan device structure 95 - * msgp ptr to msg buffer 96 - * 97 - * Returns: 98 - * 0 success and done 99 - * <0 success, but we're waiting for something to finish. 100 - * >0 an error occurred while handling the message. 101 - * Side effects: 102 - * 103 - * Call context: 104 - * process thread (usually) 105 - * interrupt 106 - *---------------------------------------------------------------- 107 - */ 108 - int prism2mgmt_scan(struct wlandevice *wlandev, void *msgp) 109 - { 110 - int result = 0; 111 - struct hfa384x *hw = wlandev->priv; 112 - struct p80211msg_dot11req_scan *msg = msgp; 113 - u16 roamingmode, word; 114 - int i, timeout; 115 - int istmpenable = 0; 116 - 117 - struct hfa384x_host_scan_request_data scanreq; 118 - 119 - /* gatekeeper check */ 120 - if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major, 121 - hw->ident_sta_fw.minor, 122 - hw->ident_sta_fw.variant) < 123 - HFA384x_FIRMWARE_VERSION(1, 3, 2)) { 124 - netdev_err(wlandev->netdev, 125 - "HostScan not supported with current firmware (<1.3.2).\n"); 126 - result = 1; 127 - msg->resultcode.data = P80211ENUM_resultcode_not_supported; 128 - goto exit; 129 - } 130 - 131 - memset(&scanreq, 0, sizeof(scanreq)); 132 - 133 - /* save current roaming mode */ 134 - result = hfa384x_drvr_getconfig16(hw, 135 - HFA384x_RID_CNFROAMINGMODE, 136 - &roamingmode); 137 - if (result) { 138 - netdev_err(wlandev->netdev, 139 - "getconfig(ROAMMODE) failed. result=%d\n", result); 140 - msg->resultcode.data = 141 - P80211ENUM_resultcode_implementation_failure; 142 - goto exit; 143 - } 144 - 145 - /* drop into mode 3 for the scan */ 146 - result = hfa384x_drvr_setconfig16(hw, 147 - HFA384x_RID_CNFROAMINGMODE, 148 - HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM); 149 - if (result) { 150 - netdev_err(wlandev->netdev, 151 - "setconfig(ROAMINGMODE) failed. result=%d\n", 152 - result); 153 - msg->resultcode.data = 154 - P80211ENUM_resultcode_implementation_failure; 155 - goto exit; 156 - } 157 - 158 - /* active or passive? */ 159 - if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major, 160 - hw->ident_sta_fw.minor, 161 - hw->ident_sta_fw.variant) > 162 - HFA384x_FIRMWARE_VERSION(1, 5, 0)) { 163 - if (msg->scantype.data != P80211ENUM_scantype_active) 164 - word = msg->maxchanneltime.data; 165 - else 166 - word = 0; 167 - 168 - result = 169 - hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPASSIVESCANCTRL, 170 - word); 171 - if (result) { 172 - netdev_warn(wlandev->netdev, 173 - "Passive scan not supported with current firmware. (<1.5.1)\n"); 174 - } 175 - } 176 - 177 - /* set up the txrate to be 2MBPS. Should be fastest basicrate... */ 178 - word = HFA384x_RATEBIT_2; 179 - scanreq.tx_rate = cpu_to_le16(word); 180 - 181 - /* set up the channel list */ 182 - word = 0; 183 - for (i = 0; i < msg->channellist.data.len; i++) { 184 - u8 channel = msg->channellist.data.data[i]; 185 - 186 - if (channel > 14) 187 - continue; 188 - /* channel 1 is BIT 0 ... channel 14 is BIT 13 */ 189 - word |= (1 << (channel - 1)); 190 - } 191 - scanreq.channel_list = cpu_to_le16(word); 192 - 193 - /* set up the ssid, if present. */ 194 - scanreq.ssid.len = cpu_to_le16(msg->ssid.data.len); 195 - memcpy(scanreq.ssid.data, msg->ssid.data.data, msg->ssid.data.len); 196 - 197 - /* Enable the MAC port if it's not already enabled */ 198 - result = hfa384x_drvr_getconfig16(hw, HFA384x_RID_PORTSTATUS, &word); 199 - if (result) { 200 - netdev_err(wlandev->netdev, 201 - "getconfig(PORTSTATUS) failed. result=%d\n", result); 202 - msg->resultcode.data = 203 - P80211ENUM_resultcode_implementation_failure; 204 - goto exit; 205 - } 206 - if (word == HFA384x_PORTSTATUS_DISABLED) { 207 - __le16 wordbuf[17]; 208 - 209 - result = hfa384x_drvr_setconfig16(hw, 210 - HFA384x_RID_CNFROAMINGMODE, 211 - HFA384x_ROAMMODE_HOSTSCAN_HOSTROAM); 212 - if (result) { 213 - netdev_err(wlandev->netdev, 214 - "setconfig(ROAMINGMODE) failed. result=%d\n", 215 - result); 216 - msg->resultcode.data = 217 - P80211ENUM_resultcode_implementation_failure; 218 - goto exit; 219 - } 220 - /* Construct a bogus SSID and assign it to OwnSSID and 221 - * DesiredSSID 222 - */ 223 - wordbuf[0] = cpu_to_le16(WLAN_SSID_MAXLEN); 224 - get_random_bytes(&wordbuf[1], WLAN_SSID_MAXLEN); 225 - result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID, 226 - wordbuf, 227 - HFA384x_RID_CNFOWNSSID_LEN); 228 - if (result) { 229 - netdev_err(wlandev->netdev, "Failed to set OwnSSID.\n"); 230 - msg->resultcode.data = 231 - P80211ENUM_resultcode_implementation_failure; 232 - goto exit; 233 - } 234 - result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID, 235 - wordbuf, 236 - HFA384x_RID_CNFDESIREDSSID_LEN); 237 - if (result) { 238 - netdev_err(wlandev->netdev, 239 - "Failed to set DesiredSSID.\n"); 240 - msg->resultcode.data = 241 - P80211ENUM_resultcode_implementation_failure; 242 - goto exit; 243 - } 244 - /* bsstype */ 245 - result = hfa384x_drvr_setconfig16(hw, 246 - HFA384x_RID_CNFPORTTYPE, 247 - HFA384x_PORTTYPE_IBSS); 248 - if (result) { 249 - netdev_err(wlandev->netdev, 250 - "Failed to set CNFPORTTYPE.\n"); 251 - msg->resultcode.data = 252 - P80211ENUM_resultcode_implementation_failure; 253 - goto exit; 254 - } 255 - /* ibss options */ 256 - result = hfa384x_drvr_setconfig16(hw, 257 - HFA384x_RID_CREATEIBSS, 258 - HFA384x_CREATEIBSS_JOINCREATEIBSS); 259 - if (result) { 260 - netdev_err(wlandev->netdev, 261 - "Failed to set CREATEIBSS.\n"); 262 - msg->resultcode.data = 263 - P80211ENUM_resultcode_implementation_failure; 264 - goto exit; 265 - } 266 - result = hfa384x_drvr_enable(hw, 0); 267 - if (result) { 268 - netdev_err(wlandev->netdev, 269 - "drvr_enable(0) failed. result=%d\n", 270 - result); 271 - msg->resultcode.data = 272 - P80211ENUM_resultcode_implementation_failure; 273 - goto exit; 274 - } 275 - istmpenable = 1; 276 - } 277 - 278 - /* Figure out our timeout first Kus, then HZ */ 279 - timeout = msg->channellist.data.len * msg->maxchanneltime.data; 280 - timeout = (timeout * HZ) / 1000; 281 - 282 - /* Issue the scan request */ 283 - hw->scanflag = 0; 284 - 285 - result = hfa384x_drvr_setconfig(hw, 286 - HFA384x_RID_HOSTSCAN, &scanreq, 287 - sizeof(scanreq)); 288 - if (result) { 289 - netdev_err(wlandev->netdev, 290 - "setconfig(SCANREQUEST) failed. result=%d\n", 291 - result); 292 - msg->resultcode.data = 293 - P80211ENUM_resultcode_implementation_failure; 294 - goto exit; 295 - } 296 - 297 - /* sleep until info frame arrives */ 298 - wait_event_interruptible_timeout(hw->cmdq, hw->scanflag, timeout); 299 - 300 - msg->numbss.status = P80211ENUM_msgitem_status_data_ok; 301 - if (hw->scanflag == -1) 302 - hw->scanflag = 0; 303 - 304 - msg->numbss.data = hw->scanflag; 305 - 306 - hw->scanflag = 0; 307 - 308 - /* Disable port if we temporarily enabled it. */ 309 - if (istmpenable) { 310 - result = hfa384x_drvr_disable(hw, 0); 311 - if (result) { 312 - netdev_err(wlandev->netdev, 313 - "drvr_disable(0) failed. result=%d\n", 314 - result); 315 - msg->resultcode.data = 316 - P80211ENUM_resultcode_implementation_failure; 317 - goto exit; 318 - } 319 - } 320 - 321 - /* restore original roaming mode */ 322 - result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFROAMINGMODE, 323 - roamingmode); 324 - if (result) { 325 - netdev_err(wlandev->netdev, 326 - "setconfig(ROAMMODE) failed. result=%d\n", result); 327 - msg->resultcode.data = 328 - P80211ENUM_resultcode_implementation_failure; 329 - goto exit; 330 - } 331 - 332 - result = 0; 333 - msg->resultcode.data = P80211ENUM_resultcode_success; 334 - 335 - exit: 336 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 337 - 338 - return result; 339 - } 340 - 341 - /*---------------------------------------------------------------- 342 - * prism2mgmt_scan_results 343 - * 344 - * Retrieve the BSS description for one of the BSSs identified in 345 - * a scan. 346 - * 347 - * Arguments: 348 - * wlandev wlan device structure 349 - * msgp ptr to msg buffer 350 - * 351 - * Returns: 352 - * 0 success and done 353 - * <0 success, but we're waiting for something to finish. 354 - * >0 an error occurred while handling the message. 355 - * Side effects: 356 - * 357 - * Call context: 358 - * process thread (usually) 359 - * interrupt 360 - *---------------------------------------------------------------- 361 - */ 362 - int prism2mgmt_scan_results(struct wlandevice *wlandev, void *msgp) 363 - { 364 - int result = 0; 365 - struct p80211msg_dot11req_scan_results *req; 366 - struct hfa384x *hw = wlandev->priv; 367 - struct hfa384x_hscan_result_sub *item = NULL; 368 - 369 - int count; 370 - 371 - req = msgp; 372 - 373 - req->resultcode.status = P80211ENUM_msgitem_status_data_ok; 374 - 375 - if (!hw->scanresults) { 376 - netdev_err(wlandev->netdev, 377 - "dot11req_scan_results can only be used after a successful dot11req_scan.\n"); 378 - result = 2; 379 - req->resultcode.data = P80211ENUM_resultcode_invalid_parameters; 380 - goto exit; 381 - } 382 - 383 - count = (hw->scanresults->framelen - 3) / 32; 384 - if (count > HFA384x_SCANRESULT_MAX) 385 - count = HFA384x_SCANRESULT_MAX; 386 - 387 - if (req->bssindex.data >= count) { 388 - netdev_dbg(wlandev->netdev, 389 - "requested index (%d) out of range (%d)\n", 390 - req->bssindex.data, count); 391 - result = 2; 392 - req->resultcode.data = P80211ENUM_resultcode_invalid_parameters; 393 - goto exit; 394 - } 395 - 396 - item = &hw->scanresults->info.hscanresult.result[req->bssindex.data]; 397 - /* signal and noise */ 398 - req->signal.status = P80211ENUM_msgitem_status_data_ok; 399 - req->noise.status = P80211ENUM_msgitem_status_data_ok; 400 - req->signal.data = le16_to_cpu(item->sl); 401 - req->noise.data = le16_to_cpu(item->anl); 402 - 403 - /* BSSID */ 404 - req->bssid.status = P80211ENUM_msgitem_status_data_ok; 405 - req->bssid.data.len = WLAN_BSSID_LEN; 406 - memcpy(req->bssid.data.data, item->bssid, WLAN_BSSID_LEN); 407 - 408 - /* SSID */ 409 - req->ssid.status = P80211ENUM_msgitem_status_data_ok; 410 - req->ssid.data.len = le16_to_cpu(item->ssid.len); 411 - req->ssid.data.len = min_t(u16, req->ssid.data.len, WLAN_SSID_MAXLEN); 412 - memcpy(req->ssid.data.data, item->ssid.data, req->ssid.data.len); 413 - 414 - /* supported rates */ 415 - for (count = 0; count < 10; count++) 416 - if (item->supprates[count] == 0) 417 - break; 418 - 419 - for (int i = 0; i < 8; i++) { 420 - if (count > i && 421 - DOT11_RATE5_ISBASIC_GET(item->supprates[i])) { 422 - req->basicrate[i].data = item->supprates[i]; 423 - req->basicrate[i].status = 424 - P80211ENUM_msgitem_status_data_ok; 425 - } 426 - } 427 - 428 - for (int i = 0; i < 8; i++) { 429 - if (count > i) { 430 - req->supprate[i].data = item->supprates[i]; 431 - req->supprate[i].status = 432 - P80211ENUM_msgitem_status_data_ok; 433 - } 434 - } 435 - 436 - /* beacon period */ 437 - req->beaconperiod.status = P80211ENUM_msgitem_status_data_ok; 438 - req->beaconperiod.data = le16_to_cpu(item->bcnint); 439 - 440 - /* timestamps */ 441 - req->timestamp.status = P80211ENUM_msgitem_status_data_ok; 442 - req->timestamp.data = jiffies; 443 - req->localtime.status = P80211ENUM_msgitem_status_data_ok; 444 - req->localtime.data = jiffies; 445 - 446 - /* atim window */ 447 - req->ibssatimwindow.status = P80211ENUM_msgitem_status_data_ok; 448 - req->ibssatimwindow.data = le16_to_cpu(item->atim); 449 - 450 - /* Channel */ 451 - req->dschannel.status = P80211ENUM_msgitem_status_data_ok; 452 - req->dschannel.data = le16_to_cpu(item->chid); 453 - 454 - /* capinfo bits */ 455 - count = le16_to_cpu(item->capinfo); 456 - req->capinfo.status = P80211ENUM_msgitem_status_data_ok; 457 - req->capinfo.data = count; 458 - 459 - /* privacy flag */ 460 - req->privacy.status = P80211ENUM_msgitem_status_data_ok; 461 - req->privacy.data = WLAN_GET_MGMT_CAP_INFO_PRIVACY(count); 462 - 463 - /* cfpollable */ 464 - req->cfpollable.status = P80211ENUM_msgitem_status_data_ok; 465 - req->cfpollable.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLABLE(count); 466 - 467 - /* cfpollreq */ 468 - req->cfpollreq.status = P80211ENUM_msgitem_status_data_ok; 469 - req->cfpollreq.data = WLAN_GET_MGMT_CAP_INFO_CFPOLLREQ(count); 470 - 471 - /* bsstype */ 472 - req->bsstype.status = P80211ENUM_msgitem_status_data_ok; 473 - req->bsstype.data = (WLAN_GET_MGMT_CAP_INFO_ESS(count)) ? 474 - P80211ENUM_bsstype_infrastructure : P80211ENUM_bsstype_independent; 475 - 476 - result = 0; 477 - req->resultcode.data = P80211ENUM_resultcode_success; 478 - 479 - exit: 480 - return result; 481 - } 482 - 483 - /*---------------------------------------------------------------- 484 - * prism2mgmt_start 485 - * 486 - * Start a BSS. Any station can do this for IBSS, only AP for ESS. 487 - * 488 - * Arguments: 489 - * wlandev wlan device structure 490 - * msgp ptr to msg buffer 491 - * 492 - * Returns: 493 - * 0 success and done 494 - * <0 success, but we're waiting for something to finish. 495 - * >0 an error occurred while handling the message. 496 - * Side effects: 497 - * 498 - * Call context: 499 - * process thread (usually) 500 - * interrupt 501 - *---------------------------------------------------------------- 502 - */ 503 - int prism2mgmt_start(struct wlandevice *wlandev, void *msgp) 504 - { 505 - int result = 0; 506 - struct hfa384x *hw = wlandev->priv; 507 - struct p80211msg_dot11req_start *msg = msgp; 508 - 509 - struct p80211pstrd *pstr; 510 - u8 bytebuf[80]; 511 - struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *)bytebuf; 512 - u16 word; 513 - 514 - wlandev->macmode = WLAN_MACMODE_NONE; 515 - 516 - /* Set the SSID */ 517 - memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data)); 518 - 519 - /*** ADHOC IBSS ***/ 520 - /* see if current f/w is less than 8c3 */ 521 - if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major, 522 - hw->ident_sta_fw.minor, 523 - hw->ident_sta_fw.variant) < 524 - HFA384x_FIRMWARE_VERSION(0, 8, 3)) { 525 - /* Ad-Hoc not quite supported on Prism2 */ 526 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 527 - msg->resultcode.data = P80211ENUM_resultcode_not_supported; 528 - goto done; 529 - } 530 - 531 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 532 - 533 - /*** STATION ***/ 534 - /* Set the REQUIRED config items */ 535 - /* SSID */ 536 - pstr = (struct p80211pstrd *)&msg->ssid.data; 537 - prism2mgmt_pstr2bytestr(p2bytestr, pstr); 538 - result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFOWNSSID, 539 - bytebuf, HFA384x_RID_CNFOWNSSID_LEN); 540 - if (result) { 541 - netdev_err(wlandev->netdev, "Failed to set CnfOwnSSID\n"); 542 - goto failed; 543 - } 544 - result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID, 545 - bytebuf, 546 - HFA384x_RID_CNFDESIREDSSID_LEN); 547 - if (result) { 548 - netdev_err(wlandev->netdev, "Failed to set CnfDesiredSSID\n"); 549 - goto failed; 550 - } 551 - 552 - /* bsstype - we use the default in the ap firmware */ 553 - /* IBSS port */ 554 - hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, 0); 555 - 556 - /* beacon period */ 557 - word = msg->beaconperiod.data; 558 - result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAPBCNINT, word); 559 - if (result) { 560 - netdev_err(wlandev->netdev, 561 - "Failed to set beacon period=%d.\n", word); 562 - goto failed; 563 - } 564 - 565 - /* dschannel */ 566 - word = msg->dschannel.data; 567 - result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFOWNCHANNEL, word); 568 - if (result) { 569 - netdev_err(wlandev->netdev, 570 - "Failed to set channel=%d.\n", word); 571 - goto failed; 572 - } 573 - /* Basic rates */ 574 - word = p80211rate_to_p2bit(msg->basicrate1.data); 575 - if (msg->basicrate2.status == P80211ENUM_msgitem_status_data_ok) 576 - word |= p80211rate_to_p2bit(msg->basicrate2.data); 577 - 578 - if (msg->basicrate3.status == P80211ENUM_msgitem_status_data_ok) 579 - word |= p80211rate_to_p2bit(msg->basicrate3.data); 580 - 581 - if (msg->basicrate4.status == P80211ENUM_msgitem_status_data_ok) 582 - word |= p80211rate_to_p2bit(msg->basicrate4.data); 583 - 584 - if (msg->basicrate5.status == P80211ENUM_msgitem_status_data_ok) 585 - word |= p80211rate_to_p2bit(msg->basicrate5.data); 586 - 587 - if (msg->basicrate6.status == P80211ENUM_msgitem_status_data_ok) 588 - word |= p80211rate_to_p2bit(msg->basicrate6.data); 589 - 590 - if (msg->basicrate7.status == P80211ENUM_msgitem_status_data_ok) 591 - word |= p80211rate_to_p2bit(msg->basicrate7.data); 592 - 593 - if (msg->basicrate8.status == P80211ENUM_msgitem_status_data_ok) 594 - word |= p80211rate_to_p2bit(msg->basicrate8.data); 595 - 596 - result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFBASICRATES, word); 597 - if (result) { 598 - netdev_err(wlandev->netdev, 599 - "Failed to set basicrates=%d.\n", word); 600 - goto failed; 601 - } 602 - 603 - /* Operational rates (supprates and txratecontrol) */ 604 - word = p80211rate_to_p2bit(msg->operationalrate1.data); 605 - if (msg->operationalrate2.status == P80211ENUM_msgitem_status_data_ok) 606 - word |= p80211rate_to_p2bit(msg->operationalrate2.data); 607 - 608 - if (msg->operationalrate3.status == P80211ENUM_msgitem_status_data_ok) 609 - word |= p80211rate_to_p2bit(msg->operationalrate3.data); 610 - 611 - if (msg->operationalrate4.status == P80211ENUM_msgitem_status_data_ok) 612 - word |= p80211rate_to_p2bit(msg->operationalrate4.data); 613 - 614 - if (msg->operationalrate5.status == P80211ENUM_msgitem_status_data_ok) 615 - word |= p80211rate_to_p2bit(msg->operationalrate5.data); 616 - 617 - if (msg->operationalrate6.status == P80211ENUM_msgitem_status_data_ok) 618 - word |= p80211rate_to_p2bit(msg->operationalrate6.data); 619 - 620 - if (msg->operationalrate7.status == P80211ENUM_msgitem_status_data_ok) 621 - word |= p80211rate_to_p2bit(msg->operationalrate7.data); 622 - 623 - if (msg->operationalrate8.status == P80211ENUM_msgitem_status_data_ok) 624 - word |= p80211rate_to_p2bit(msg->operationalrate8.data); 625 - 626 - result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFSUPPRATES, word); 627 - if (result) { 628 - netdev_err(wlandev->netdev, 629 - "Failed to set supprates=%d.\n", word); 630 - goto failed; 631 - } 632 - 633 - result = hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, word); 634 - if (result) { 635 - netdev_err(wlandev->netdev, "Failed to set txrates=%d.\n", 636 - word); 637 - goto failed; 638 - } 639 - 640 - /* Set the macmode so the frame setup code knows what to do */ 641 - if (msg->bsstype.data == P80211ENUM_bsstype_independent) { 642 - wlandev->macmode = WLAN_MACMODE_IBSS_STA; 643 - /* lets extend the data length a bit */ 644 - hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 2304); 645 - } 646 - 647 - /* Enable the Port */ 648 - result = hfa384x_drvr_enable(hw, 0); 649 - if (result) { 650 - netdev_err(wlandev->netdev, 651 - "Enable macport failed, result=%d.\n", result); 652 - goto failed; 653 - } 654 - 655 - msg->resultcode.data = P80211ENUM_resultcode_success; 656 - 657 - goto done; 658 - failed: 659 - netdev_dbg(wlandev->netdev, 660 - "Failed to set a config option, result=%d\n", result); 661 - msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters; 662 - 663 - done: 664 - return 0; 665 - } 666 - 667 - /*---------------------------------------------------------------- 668 - * prism2mgmt_readpda 669 - * 670 - * Collect the PDA data and put it in the message. 671 - * 672 - * Arguments: 673 - * wlandev wlan device structure 674 - * msgp ptr to msg buffer 675 - * 676 - * Returns: 677 - * 0 success and done 678 - * <0 success, but we're waiting for something to finish. 679 - * >0 an error occurred while handling the message. 680 - * Side effects: 681 - * 682 - * Call context: 683 - * process thread (usually) 684 - *---------------------------------------------------------------- 685 - */ 686 - int prism2mgmt_readpda(struct wlandevice *wlandev, void *msgp) 687 - { 688 - struct hfa384x *hw = wlandev->priv; 689 - struct p80211msg_p2req_readpda *msg = msgp; 690 - int result; 691 - 692 - /* We only support collecting the PDA when in the FWLOAD 693 - * state. 694 - */ 695 - if (wlandev->msdstate != WLAN_MSD_FWLOAD) { 696 - netdev_err(wlandev->netdev, 697 - "PDA may only be read in the fwload state.\n"); 698 - msg->resultcode.data = 699 - P80211ENUM_resultcode_implementation_failure; 700 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 701 - } else { 702 - /* Call drvr_readpda(), it handles the auxport enable 703 - * and validating the returned PDA. 704 - */ 705 - result = hfa384x_drvr_readpda(hw, 706 - msg->pda.data, 707 - HFA384x_PDA_LEN_MAX); 708 - if (result) { 709 - netdev_err(wlandev->netdev, 710 - "hfa384x_drvr_readpda() failed, result=%d\n", 711 - result); 712 - 713 - msg->resultcode.data = 714 - P80211ENUM_resultcode_implementation_failure; 715 - msg->resultcode.status = 716 - P80211ENUM_msgitem_status_data_ok; 717 - return 0; 718 - } 719 - msg->pda.status = P80211ENUM_msgitem_status_data_ok; 720 - msg->resultcode.data = P80211ENUM_resultcode_success; 721 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 722 - } 723 - 724 - return 0; 725 - } 726 - 727 - /*---------------------------------------------------------------- 728 - * prism2mgmt_ramdl_state 729 - * 730 - * Establishes the beginning/end of a card RAM download session. 731 - * 732 - * It is expected that the ramdl_write() function will be called 733 - * one or more times between the 'enable' and 'disable' calls to 734 - * this function. 735 - * 736 - * Note: This function should not be called when a mac comm port 737 - * is active. 738 - * 739 - * Arguments: 740 - * wlandev wlan device structure 741 - * msgp ptr to msg buffer 742 - * 743 - * Returns: 744 - * 0 success and done 745 - * <0 success, but we're waiting for something to finish. 746 - * >0 an error occurred while handling the message. 747 - * Side effects: 748 - * 749 - * Call context: 750 - * process thread (usually) 751 - *---------------------------------------------------------------- 752 - */ 753 - int prism2mgmt_ramdl_state(struct wlandevice *wlandev, void *msgp) 754 - { 755 - struct hfa384x *hw = wlandev->priv; 756 - struct p80211msg_p2req_ramdl_state *msg = msgp; 757 - 758 - if (wlandev->msdstate != WLAN_MSD_FWLOAD) { 759 - netdev_err(wlandev->netdev, 760 - "ramdl_state(): may only be called in the fwload state.\n"); 761 - msg->resultcode.data = 762 - P80211ENUM_resultcode_implementation_failure; 763 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 764 - return 0; 765 - } 766 - 767 - /* 768 - ** Note: Interrupts are locked out if this is an AP and are NOT 769 - ** locked out if this is a station. 770 - */ 771 - 772 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 773 - if (msg->enable.data == P80211ENUM_truth_true) { 774 - if (hfa384x_drvr_ramdl_enable(hw, msg->exeaddr.data)) { 775 - msg->resultcode.data = 776 - P80211ENUM_resultcode_implementation_failure; 777 - } else { 778 - msg->resultcode.data = P80211ENUM_resultcode_success; 779 - } 780 - } else { 781 - hfa384x_drvr_ramdl_disable(hw); 782 - msg->resultcode.data = P80211ENUM_resultcode_success; 783 - } 784 - 785 - return 0; 786 - } 787 - 788 - /*---------------------------------------------------------------- 789 - * prism2mgmt_ramdl_write 790 - * 791 - * Writes a buffer to the card RAM using the download state. This 792 - * is for writing code to card RAM. To just read or write raw data 793 - * use the aux functions. 794 - * 795 - * Arguments: 796 - * wlandev wlan device structure 797 - * msgp ptr to msg buffer 798 - * 799 - * Returns: 800 - * 0 success and done 801 - * <0 success, but we're waiting for something to finish. 802 - * >0 an error occurred while handling the message. 803 - * Side effects: 804 - * 805 - * Call context: 806 - * process thread (usually) 807 - *---------------------------------------------------------------- 808 - */ 809 - int prism2mgmt_ramdl_write(struct wlandevice *wlandev, void *msgp) 810 - { 811 - struct hfa384x *hw = wlandev->priv; 812 - struct p80211msg_p2req_ramdl_write *msg = msgp; 813 - u32 addr; 814 - u32 len; 815 - u8 *buf; 816 - 817 - if (wlandev->msdstate != WLAN_MSD_FWLOAD) { 818 - netdev_err(wlandev->netdev, 819 - "ramdl_write(): may only be called in the fwload state.\n"); 820 - msg->resultcode.data = 821 - P80211ENUM_resultcode_implementation_failure; 822 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 823 - return 0; 824 - } 825 - 826 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 827 - /* first validate the length */ 828 - if (msg->len.data > sizeof(msg->data.data)) { 829 - msg->resultcode.status = 830 - P80211ENUM_resultcode_invalid_parameters; 831 - return 0; 832 - } 833 - /* call the hfa384x function to do the write */ 834 - addr = msg->addr.data; 835 - len = msg->len.data; 836 - buf = msg->data.data; 837 - if (hfa384x_drvr_ramdl_write(hw, addr, buf, len)) 838 - msg->resultcode.data = P80211ENUM_resultcode_refused; 839 - 840 - msg->resultcode.data = P80211ENUM_resultcode_success; 841 - 842 - return 0; 843 - } 844 - 845 - /*---------------------------------------------------------------- 846 - * prism2mgmt_flashdl_state 847 - * 848 - * Establishes the beginning/end of a card Flash download session. 849 - * 850 - * It is expected that the flashdl_write() function will be called 851 - * one or more times between the 'enable' and 'disable' calls to 852 - * this function. 853 - * 854 - * Note: This function should not be called when a mac comm port 855 - * is active. 856 - * 857 - * Arguments: 858 - * wlandev wlan device structure 859 - * msgp ptr to msg buffer 860 - * 861 - * Returns: 862 - * 0 success and done 863 - * <0 success, but we're waiting for something to finish. 864 - * >0 an error occurred while handling the message. 865 - * Side effects: 866 - * 867 - * Call context: 868 - * process thread (usually) 869 - *---------------------------------------------------------------- 870 - */ 871 - int prism2mgmt_flashdl_state(struct wlandevice *wlandev, void *msgp) 872 - { 873 - int result = 0; 874 - struct hfa384x *hw = wlandev->priv; 875 - struct p80211msg_p2req_flashdl_state *msg = msgp; 876 - 877 - if (wlandev->msdstate != WLAN_MSD_FWLOAD) { 878 - netdev_err(wlandev->netdev, 879 - "flashdl_state(): may only be called in the fwload state.\n"); 880 - msg->resultcode.data = 881 - P80211ENUM_resultcode_implementation_failure; 882 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 883 - return 0; 884 - } 885 - 886 - /* 887 - ** Note: Interrupts are locked out if this is an AP and are NOT 888 - ** locked out if this is a station. 889 - */ 890 - 891 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 892 - if (msg->enable.data == P80211ENUM_truth_true) { 893 - if (hfa384x_drvr_flashdl_enable(hw)) { 894 - msg->resultcode.data = 895 - P80211ENUM_resultcode_implementation_failure; 896 - } else { 897 - msg->resultcode.data = P80211ENUM_resultcode_success; 898 - } 899 - } else { 900 - hfa384x_drvr_flashdl_disable(hw); 901 - msg->resultcode.data = P80211ENUM_resultcode_success; 902 - /* NOTE: At this point, the MAC is in the post-reset 903 - * state and the driver is in the fwload state. 904 - * We need to get the MAC back into the fwload 905 - * state. To do this, we set the nsdstate to HWPRESENT 906 - * and then call the ifstate function to redo everything 907 - * that got us into the fwload state. 908 - */ 909 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 910 - result = prism2sta_ifstate(wlandev, P80211ENUM_ifstate_fwload); 911 - if (result != P80211ENUM_resultcode_success) { 912 - netdev_err(wlandev->netdev, 913 - "prism2sta_ifstate(fwload) failed, P80211ENUM_resultcode=%d\n", 914 - result); 915 - msg->resultcode.data = 916 - P80211ENUM_resultcode_implementation_failure; 917 - result = -1; 918 - } 919 - } 920 - 921 - return result; 922 - } 923 - 924 - /*---------------------------------------------------------------- 925 - * prism2mgmt_flashdl_write 926 - * 927 - * 928 - * 929 - * Arguments: 930 - * wlandev wlan device structure 931 - * msgp ptr to msg buffer 932 - * 933 - * Returns: 934 - * 0 success and done 935 - * <0 success, but we're waiting for something to finish. 936 - * >0 an error occurred while handling the message. 937 - * Side effects: 938 - * 939 - * Call context: 940 - * process thread (usually) 941 - *---------------------------------------------------------------- 942 - */ 943 - int prism2mgmt_flashdl_write(struct wlandevice *wlandev, void *msgp) 944 - { 945 - struct hfa384x *hw = wlandev->priv; 946 - struct p80211msg_p2req_flashdl_write *msg = msgp; 947 - u32 addr; 948 - u32 len; 949 - u8 *buf; 950 - 951 - if (wlandev->msdstate != WLAN_MSD_FWLOAD) { 952 - netdev_err(wlandev->netdev, 953 - "flashdl_write(): may only be called in the fwload state.\n"); 954 - msg->resultcode.data = 955 - P80211ENUM_resultcode_implementation_failure; 956 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 957 - return 0; 958 - } 959 - 960 - /* 961 - ** Note: Interrupts are locked out if this is an AP and are NOT 962 - ** locked out if this is a station. 963 - */ 964 - 965 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 966 - /* first validate the length */ 967 - if (msg->len.data > sizeof(msg->data.data)) { 968 - msg->resultcode.status = 969 - P80211ENUM_resultcode_invalid_parameters; 970 - return 0; 971 - } 972 - /* call the hfa384x function to do the write */ 973 - addr = msg->addr.data; 974 - len = msg->len.data; 975 - buf = msg->data.data; 976 - if (hfa384x_drvr_flashdl_write(hw, addr, buf, len)) 977 - msg->resultcode.data = P80211ENUM_resultcode_refused; 978 - 979 - msg->resultcode.data = P80211ENUM_resultcode_success; 980 - 981 - return 0; 982 - } 983 - 984 - /*---------------------------------------------------------------- 985 - * prism2mgmt_autojoin 986 - * 987 - * Associate with an ESS. 988 - * 989 - * Arguments: 990 - * wlandev wlan device structure 991 - * msgp ptr to msg buffer 992 - * 993 - * Returns: 994 - * 0 success and done 995 - * <0 success, but we're waiting for something to finish. 996 - * >0 an error occurred while handling the message. 997 - * Side effects: 998 - * 999 - * Call context: 1000 - * process thread (usually) 1001 - * interrupt 1002 - *---------------------------------------------------------------- 1003 - */ 1004 - int prism2mgmt_autojoin(struct wlandevice *wlandev, void *msgp) 1005 - { 1006 - struct hfa384x *hw = wlandev->priv; 1007 - int result = 0; 1008 - u16 reg; 1009 - u16 port_type; 1010 - struct p80211msg_lnxreq_autojoin *msg = msgp; 1011 - struct p80211pstrd *pstr; 1012 - u8 bytebuf[256]; 1013 - struct hfa384x_bytestr *p2bytestr = (struct hfa384x_bytestr *)bytebuf; 1014 - 1015 - wlandev->macmode = WLAN_MACMODE_NONE; 1016 - 1017 - /* Set the SSID */ 1018 - memcpy(&wlandev->ssid, &msg->ssid.data, sizeof(msg->ssid.data)); 1019 - 1020 - /* Disable the Port */ 1021 - hfa384x_drvr_disable(hw, 0); 1022 - 1023 - /*** STATION ***/ 1024 - /* Set the TxRates */ 1025 - hfa384x_drvr_setconfig16(hw, HFA384x_RID_TXRATECNTL, 0x000f); 1026 - 1027 - /* Set the auth type */ 1028 - if (msg->authtype.data == P80211ENUM_authalg_sharedkey) 1029 - reg = HFA384x_CNFAUTHENTICATION_SHAREDKEY; 1030 - else 1031 - reg = HFA384x_CNFAUTHENTICATION_OPENSYSTEM; 1032 - 1033 - hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFAUTHENTICATION, reg); 1034 - 1035 - /* Set the ssid */ 1036 - memset(bytebuf, 0, 256); 1037 - pstr = (struct p80211pstrd *)&msg->ssid.data; 1038 - prism2mgmt_pstr2bytestr(p2bytestr, pstr); 1039 - result = hfa384x_drvr_setconfig(hw, HFA384x_RID_CNFDESIREDSSID, 1040 - bytebuf, 1041 - HFA384x_RID_CNFDESIREDSSID_LEN); 1042 - port_type = HFA384x_PORTTYPE_BSS; 1043 - /* Set the PortType */ 1044 - hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFPORTTYPE, port_type); 1045 - 1046 - /* Enable the Port */ 1047 - hfa384x_drvr_enable(hw, 0); 1048 - 1049 - /* Set the resultcode */ 1050 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 1051 - msg->resultcode.data = P80211ENUM_resultcode_success; 1052 - 1053 - return result; 1054 - } 1055 - 1056 - /*---------------------------------------------------------------- 1057 - * prism2mgmt_wlansniff 1058 - * 1059 - * Start or stop sniffing. 1060 - * 1061 - * Arguments: 1062 - * wlandev wlan device structure 1063 - * msgp ptr to msg buffer 1064 - * 1065 - * Returns: 1066 - * 0 success and done 1067 - * <0 success, but we're waiting for something to finish. 1068 - * >0 an error occurred while handling the message. 1069 - * Side effects: 1070 - * 1071 - * Call context: 1072 - * process thread (usually) 1073 - * interrupt 1074 - *---------------------------------------------------------------- 1075 - */ 1076 - int prism2mgmt_wlansniff(struct wlandevice *wlandev, void *msgp) 1077 - { 1078 - int result = 0; 1079 - struct p80211msg_lnxreq_wlansniff *msg = msgp; 1080 - 1081 - struct hfa384x *hw = wlandev->priv; 1082 - u16 word; 1083 - 1084 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 1085 - switch (msg->enable.data) { 1086 - case P80211ENUM_truth_false: 1087 - /* Confirm that we're in monitor mode */ 1088 - if (wlandev->netdev->type == ARPHRD_ETHER) { 1089 - msg->resultcode.data = 1090 - P80211ENUM_resultcode_invalid_parameters; 1091 - return 0; 1092 - } 1093 - /* Disable monitor mode */ 1094 - result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_DISABLE); 1095 - if (result) { 1096 - netdev_dbg(wlandev->netdev, 1097 - "failed to disable monitor mode, result=%d\n", 1098 - result); 1099 - goto failed; 1100 - } 1101 - /* Disable port 0 */ 1102 - result = hfa384x_drvr_disable(hw, 0); 1103 - if (result) { 1104 - netdev_dbg 1105 - (wlandev->netdev, 1106 - "failed to disable port 0 after sniffing, result=%d\n", 1107 - result); 1108 - goto failed; 1109 - } 1110 - /* Clear the driver state */ 1111 - wlandev->netdev->type = ARPHRD_ETHER; 1112 - 1113 - /* Restore the wepflags */ 1114 - result = hfa384x_drvr_setconfig16(hw, 1115 - HFA384x_RID_CNFWEPFLAGS, 1116 - hw->presniff_wepflags); 1117 - if (result) { 1118 - netdev_dbg 1119 - (wlandev->netdev, 1120 - "failed to restore wepflags=0x%04x, result=%d\n", 1121 - hw->presniff_wepflags, result); 1122 - goto failed; 1123 - } 1124 - 1125 - /* Set the port to its prior type and enable (if necessary) */ 1126 - if (hw->presniff_port_type != 0) { 1127 - word = hw->presniff_port_type; 1128 - result = hfa384x_drvr_setconfig16(hw, 1129 - HFA384x_RID_CNFPORTTYPE, 1130 - word); 1131 - if (result) { 1132 - netdev_dbg 1133 - (wlandev->netdev, 1134 - "failed to restore porttype, result=%d\n", 1135 - result); 1136 - goto failed; 1137 - } 1138 - 1139 - /* Enable the port */ 1140 - result = hfa384x_drvr_enable(hw, 0); 1141 - if (result) { 1142 - netdev_dbg(wlandev->netdev, 1143 - "failed to enable port to presniff setting, result=%d\n", 1144 - result); 1145 - goto failed; 1146 - } 1147 - } else { 1148 - result = hfa384x_drvr_disable(hw, 0); 1149 - } 1150 - 1151 - netdev_info(wlandev->netdev, "monitor mode disabled\n"); 1152 - msg->resultcode.data = P80211ENUM_resultcode_success; 1153 - return 0; 1154 - case P80211ENUM_truth_true: 1155 - /* Disable the port (if enabled), only check Port 0 */ 1156 - if (hw->port_enabled[0]) { 1157 - if (wlandev->netdev->type == ARPHRD_ETHER) { 1158 - /* Save macport 0 state */ 1159 - result = hfa384x_drvr_getconfig16(hw, 1160 - HFA384x_RID_CNFPORTTYPE, 1161 - &hw->presniff_port_type); 1162 - if (result) { 1163 - netdev_dbg 1164 - (wlandev->netdev, 1165 - "failed to read porttype, result=%d\n", 1166 - result); 1167 - goto failed; 1168 - } 1169 - /* Save the wepflags state */ 1170 - result = hfa384x_drvr_getconfig16(hw, 1171 - HFA384x_RID_CNFWEPFLAGS, 1172 - &hw->presniff_wepflags); 1173 - if (result) { 1174 - netdev_dbg 1175 - (wlandev->netdev, 1176 - "failed to read wepflags, result=%d\n", 1177 - result); 1178 - goto failed; 1179 - } 1180 - hfa384x_drvr_stop(hw); 1181 - result = hfa384x_drvr_start(hw); 1182 - if (result) { 1183 - netdev_dbg(wlandev->netdev, 1184 - "failed to restart the card for sniffing, result=%d\n", 1185 - result); 1186 - goto failed; 1187 - } 1188 - } else { 1189 - /* Disable the port */ 1190 - result = hfa384x_drvr_disable(hw, 0); 1191 - if (result) { 1192 - netdev_dbg(wlandev->netdev, 1193 - "failed to enable port for sniffing, result=%d\n", 1194 - result); 1195 - goto failed; 1196 - } 1197 - } 1198 - } else { 1199 - hw->presniff_port_type = 0; 1200 - } 1201 - 1202 - /* Set the channel we wish to sniff */ 1203 - word = msg->channel.data; 1204 - result = hfa384x_drvr_setconfig16(hw, 1205 - HFA384x_RID_CNFOWNCHANNEL, 1206 - word); 1207 - hw->sniff_channel = word; 1208 - 1209 - if (result) { 1210 - netdev_dbg(wlandev->netdev, 1211 - "failed to set channel %d, result=%d\n", 1212 - word, result); 1213 - goto failed; 1214 - } 1215 - 1216 - /* Now if we're already sniffing, we can skip the rest */ 1217 - if (wlandev->netdev->type != ARPHRD_ETHER) { 1218 - /* Set the port type to pIbss */ 1219 - word = HFA384x_PORTTYPE_PSUEDOIBSS; 1220 - result = hfa384x_drvr_setconfig16(hw, 1221 - HFA384x_RID_CNFPORTTYPE, 1222 - word); 1223 - if (result) { 1224 - netdev_dbg 1225 - (wlandev->netdev, 1226 - "failed to set porttype %d, result=%d\n", 1227 - word, result); 1228 - goto failed; 1229 - } 1230 - if ((msg->keepwepflags.status == 1231 - P80211ENUM_msgitem_status_data_ok) && 1232 - (msg->keepwepflags.data != P80211ENUM_truth_true)) { 1233 - /* Set the wepflags for no decryption */ 1234 - word = HFA384x_WEPFLAGS_DISABLE_TXCRYPT | 1235 - HFA384x_WEPFLAGS_DISABLE_RXCRYPT; 1236 - result = 1237 - hfa384x_drvr_setconfig16(hw, 1238 - HFA384x_RID_CNFWEPFLAGS, 1239 - word); 1240 - } 1241 - 1242 - if (result) { 1243 - netdev_dbg 1244 - (wlandev->netdev, 1245 - "failed to set wepflags=0x%04x, result=%d\n", 1246 - word, result); 1247 - goto failed; 1248 - } 1249 - } 1250 - 1251 - /* Do we want to strip the FCS in monitor mode? */ 1252 - if ((msg->stripfcs.status == 1253 - P80211ENUM_msgitem_status_data_ok) && 1254 - (msg->stripfcs.data == P80211ENUM_truth_true)) { 1255 - hw->sniff_fcs = 0; 1256 - } else { 1257 - hw->sniff_fcs = 1; 1258 - } 1259 - 1260 - /* Do we want to truncate the packets? */ 1261 - if (msg->packet_trunc.status == 1262 - P80211ENUM_msgitem_status_data_ok) { 1263 - hw->sniff_truncate = msg->packet_trunc.data; 1264 - } else { 1265 - hw->sniff_truncate = 0; 1266 - } 1267 - 1268 - /* Enable the port */ 1269 - result = hfa384x_drvr_enable(hw, 0); 1270 - if (result) { 1271 - netdev_dbg 1272 - (wlandev->netdev, 1273 - "failed to enable port for sniffing, result=%d\n", 1274 - result); 1275 - goto failed; 1276 - } 1277 - /* Enable monitor mode */ 1278 - result = hfa384x_cmd_monitor(hw, HFA384x_MONITOR_ENABLE); 1279 - if (result) { 1280 - netdev_dbg(wlandev->netdev, 1281 - "failed to enable monitor mode, result=%d\n", 1282 - result); 1283 - goto failed; 1284 - } 1285 - 1286 - if (wlandev->netdev->type == ARPHRD_ETHER) 1287 - netdev_info(wlandev->netdev, "monitor mode enabled\n"); 1288 - 1289 - /* Set the driver state */ 1290 - /* Do we want the prism2 header? */ 1291 - if ((msg->prismheader.status == 1292 - P80211ENUM_msgitem_status_data_ok) && 1293 - (msg->prismheader.data == P80211ENUM_truth_true)) { 1294 - hw->sniffhdr = 0; 1295 - wlandev->netdev->type = ARPHRD_IEEE80211_PRISM; 1296 - } else if ((msg->wlanheader.status == 1297 - P80211ENUM_msgitem_status_data_ok) && 1298 - (msg->wlanheader.data == P80211ENUM_truth_true)) { 1299 - hw->sniffhdr = 1; 1300 - wlandev->netdev->type = ARPHRD_IEEE80211_PRISM; 1301 - } else { 1302 - wlandev->netdev->type = ARPHRD_IEEE80211; 1303 - } 1304 - 1305 - msg->resultcode.data = P80211ENUM_resultcode_success; 1306 - return 0; 1307 - default: 1308 - msg->resultcode.data = P80211ENUM_resultcode_invalid_parameters; 1309 - return 0; 1310 - } 1311 - 1312 - failed: 1313 - msg->resultcode.data = P80211ENUM_resultcode_refused; 1314 - return 0; 1315 - }
-89
drivers/staging/wlan-ng/prism2mgmt.h
··· 1 - /* SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) */ 2 - /* 3 - * 4 - * Declares the mgmt command handler functions 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file contains the constants and data structures for interaction 28 - * with the hfa384x Wireless LAN (WLAN) Media Access Controller (MAC). 29 - * The hfa384x is a portion of the Harris PRISM(tm) WLAN chipset. 30 - * 31 - * [Implementation and usage notes] 32 - * 33 - * [References] 34 - * CW10 Programmer's Manual v1.5 35 - * IEEE 802.11 D10.0 36 - * 37 - * -------------------------------------------------------------------- 38 - */ 39 - 40 - #ifndef _PRISM2MGMT_H 41 - #define _PRISM2MGMT_H 42 - 43 - extern int prism2_reset_holdtime; 44 - extern int prism2_reset_settletime; 45 - 46 - u32 prism2sta_ifstate(struct wlandevice *wlandev, u32 ifstate); 47 - 48 - void prism2sta_ev_info(struct wlandevice *wlandev, struct hfa384x_inf_frame *inf); 49 - void prism2sta_ev_tx(struct wlandevice *wlandev, u16 status); 50 - void prism2sta_ev_alloc(struct wlandevice *wlandev); 51 - 52 - int prism2mgmt_mibset_mibget(struct wlandevice *wlandev, void *msgp); 53 - int prism2mgmt_scan(struct wlandevice *wlandev, void *msgp); 54 - int prism2mgmt_scan_results(struct wlandevice *wlandev, void *msgp); 55 - int prism2mgmt_start(struct wlandevice *wlandev, void *msgp); 56 - int prism2mgmt_wlansniff(struct wlandevice *wlandev, void *msgp); 57 - int prism2mgmt_readpda(struct wlandevice *wlandev, void *msgp); 58 - int prism2mgmt_ramdl_state(struct wlandevice *wlandev, void *msgp); 59 - int prism2mgmt_ramdl_write(struct wlandevice *wlandev, void *msgp); 60 - int prism2mgmt_flashdl_state(struct wlandevice *wlandev, void *msgp); 61 - int prism2mgmt_flashdl_write(struct wlandevice *wlandev, void *msgp); 62 - int prism2mgmt_autojoin(struct wlandevice *wlandev, void *msgp); 63 - 64 - /*--------------------------------------------------------------- 65 - * conversion functions going between wlan message data types and 66 - * Prism2 data types 67 - *--------------------------------------------------------------- 68 - */ 69 - 70 - /* byte area conversion functions*/ 71 - void prism2mgmt_bytearea2pstr(u8 *bytearea, struct p80211pstrd *pstr, int len); 72 - 73 - /* byte string conversion functions*/ 74 - void prism2mgmt_pstr2bytestr(struct hfa384x_bytestr *bytestr, 75 - struct p80211pstrd *pstr); 76 - void prism2mgmt_bytestr2pstr(struct hfa384x_bytestr *bytestr, 77 - struct p80211pstrd *pstr); 78 - 79 - void prism2sta_processing_defer(struct work_struct *data); 80 - 81 - void prism2sta_commsqual_defer(struct work_struct *data); 82 - void prism2sta_commsqual_timer(struct timer_list *t); 83 - 84 - /* Interface callback functions, passing data back up to the cfg80211 layer */ 85 - void prism2_connect_result(struct wlandevice *wlandev, u8 failed); 86 - void prism2_disconnected(struct wlandevice *wlandev); 87 - void prism2_roamed(struct wlandevice *wlandev); 88 - 89 - #endif
-742
drivers/staging/wlan-ng/prism2mib.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Management request for mibset/mibget 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * The functions in this file handle the mibset/mibget management 28 - * functions. 29 - * 30 - * -------------------------------------------------------------------- 31 - */ 32 - 33 - #include <linux/module.h> 34 - #include <linux/kernel.h> 35 - #include <linux/sched.h> 36 - #include <linux/types.h> 37 - #include <linux/wireless.h> 38 - #include <linux/netdevice.h> 39 - #include <linux/io.h> 40 - #include <linux/delay.h> 41 - #include <asm/byteorder.h> 42 - #include <linux/usb.h> 43 - #include <linux/bitops.h> 44 - 45 - #include "p80211types.h" 46 - #include "p80211hdr.h" 47 - #include "p80211mgmt.h" 48 - #include "p80211conv.h" 49 - #include "p80211msg.h" 50 - #include "p80211netdev.h" 51 - #include "p80211metadef.h" 52 - #include "p80211metastruct.h" 53 - #include "hfa384x.h" 54 - #include "prism2mgmt.h" 55 - 56 - #define MIB_TMP_MAXLEN 200 /* Max length of RID record (in bytes). */ 57 - 58 - #define F_STA 0x1 /* MIB is supported on stations. */ 59 - #define F_READ 0x2 /* MIB may be read. */ 60 - #define F_WRITE 0x4 /* MIB may be written. */ 61 - 62 - struct mibrec { 63 - u32 did; 64 - u16 flag; 65 - u16 parm1; 66 - u16 parm2; 67 - u16 parm3; 68 - int (*func)(struct mibrec *mib, 69 - int isget, 70 - struct wlandevice *wlandev, 71 - struct hfa384x *hw, 72 - struct p80211msg_dot11req_mibset *msg, void *data); 73 - }; 74 - 75 - static int prism2mib_bytearea2pstr(struct mibrec *mib, 76 - int isget, 77 - struct wlandevice *wlandev, 78 - struct hfa384x *hw, 79 - struct p80211msg_dot11req_mibset *msg, 80 - void *data); 81 - 82 - static int prism2mib_uint32(struct mibrec *mib, 83 - int isget, 84 - struct wlandevice *wlandev, 85 - struct hfa384x *hw, 86 - struct p80211msg_dot11req_mibset *msg, void *data); 87 - 88 - static int prism2mib_flag(struct mibrec *mib, 89 - int isget, 90 - struct wlandevice *wlandev, 91 - struct hfa384x *hw, 92 - struct p80211msg_dot11req_mibset *msg, void *data); 93 - 94 - static int prism2mib_wepdefaultkey(struct mibrec *mib, 95 - int isget, 96 - struct wlandevice *wlandev, 97 - struct hfa384x *hw, 98 - struct p80211msg_dot11req_mibset *msg, 99 - void *data); 100 - 101 - static int prism2mib_privacyinvoked(struct mibrec *mib, 102 - int isget, 103 - struct wlandevice *wlandev, 104 - struct hfa384x *hw, 105 - struct p80211msg_dot11req_mibset *msg, 106 - void *data); 107 - 108 - static int 109 - prism2mib_fragmentationthreshold(struct mibrec *mib, 110 - int isget, 111 - struct wlandevice *wlandev, 112 - struct hfa384x *hw, 113 - struct p80211msg_dot11req_mibset *msg, 114 - void *data); 115 - 116 - static int prism2mib_priv(struct mibrec *mib, 117 - int isget, 118 - struct wlandevice *wlandev, 119 - struct hfa384x *hw, 120 - struct p80211msg_dot11req_mibset *msg, void *data); 121 - 122 - static struct mibrec mibtab[] = { 123 - /* dot11smt MIB's */ 124 - {didmib_dot11smt_wepdefaultkeystable_key(1), 125 - F_STA | F_WRITE, 126 - HFA384x_RID_CNFWEPDEFAULTKEY0, 0, 0, 127 - prism2mib_wepdefaultkey}, 128 - {didmib_dot11smt_wepdefaultkeystable_key(2), 129 - F_STA | F_WRITE, 130 - HFA384x_RID_CNFWEPDEFAULTKEY1, 0, 0, 131 - prism2mib_wepdefaultkey}, 132 - {didmib_dot11smt_wepdefaultkeystable_key(3), 133 - F_STA | F_WRITE, 134 - HFA384x_RID_CNFWEPDEFAULTKEY2, 0, 0, 135 - prism2mib_wepdefaultkey}, 136 - {didmib_dot11smt_wepdefaultkeystable_key(4), 137 - F_STA | F_WRITE, 138 - HFA384x_RID_CNFWEPDEFAULTKEY3, 0, 0, 139 - prism2mib_wepdefaultkey}, 140 - {DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED, 141 - F_STA | F_READ | F_WRITE, 142 - HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_PRIVINVOKED, 0, 143 - prism2mib_privacyinvoked}, 144 - {DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, 145 - F_STA | F_READ | F_WRITE, 146 - HFA384x_RID_CNFWEPDEFAULTKEYID, 0, 0, 147 - prism2mib_uint32}, 148 - {DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED, 149 - F_STA | F_READ | F_WRITE, 150 - HFA384x_RID_CNFWEPFLAGS, HFA384x_WEPFLAGS_EXCLUDE, 0, 151 - prism2mib_flag}, 152 - 153 - /* dot11mac MIB's */ 154 - 155 - {DIDMIB_DOT11MAC_OPERATIONTABLE_MACADDRESS, 156 - F_STA | F_READ | F_WRITE, 157 - HFA384x_RID_CNFOWNMACADDR, HFA384x_RID_CNFOWNMACADDR_LEN, 0, 158 - prism2mib_bytearea2pstr}, 159 - {DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD, 160 - F_STA | F_READ | F_WRITE, 161 - HFA384x_RID_RTSTHRESH, 0, 0, 162 - prism2mib_uint32}, 163 - {DIDMIB_DOT11MAC_OPERATIONTABLE_SHORTRETRYLIMIT, 164 - F_STA | F_READ, 165 - HFA384x_RID_SHORTRETRYLIMIT, 0, 0, 166 - prism2mib_uint32}, 167 - {DIDMIB_DOT11MAC_OPERATIONTABLE_LONGRETRYLIMIT, 168 - F_STA | F_READ, 169 - HFA384x_RID_LONGRETRYLIMIT, 0, 0, 170 - prism2mib_uint32}, 171 - {DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD, 172 - F_STA | F_READ | F_WRITE, 173 - HFA384x_RID_FRAGTHRESH, 0, 0, 174 - prism2mib_fragmentationthreshold}, 175 - {DIDMIB_DOT11MAC_OPERATIONTABLE_MAXTRANSMITMSDULIFETIME, 176 - F_STA | F_READ, 177 - HFA384x_RID_MAXTXLIFETIME, 0, 0, 178 - prism2mib_uint32}, 179 - 180 - /* dot11phy MIB's */ 181 - 182 - {DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL, 183 - F_STA | F_READ, 184 - HFA384x_RID_CURRENTCHANNEL, 0, 0, 185 - prism2mib_uint32}, 186 - {DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL, 187 - F_STA | F_READ | F_WRITE, 188 - HFA384x_RID_TXPOWERMAX, 0, 0, 189 - prism2mib_uint32}, 190 - 191 - /* p2Static MIB's */ 192 - 193 - {DIDMIB_P2_STATIC_CNFPORTTYPE, 194 - F_STA | F_READ | F_WRITE, 195 - HFA384x_RID_CNFPORTTYPE, 0, 0, 196 - prism2mib_uint32}, 197 - 198 - /* p2MAC MIB's */ 199 - 200 - {DIDMIB_P2_MAC_CURRENTTXRATE, 201 - F_STA | F_READ, 202 - HFA384x_RID_CURRENTTXRATE, 0, 0, 203 - prism2mib_uint32}, 204 - 205 - /* And finally, lnx mibs */ 206 - {DIDMIB_LNX_CONFIGTABLE_RSNAIE, 207 - F_STA | F_READ | F_WRITE, 208 - HFA384x_RID_CNFWPADATA, 0, 0, 209 - prism2mib_priv}, 210 - {0, 0, 0, 0, 0, NULL} 211 - }; 212 - 213 - /* 214 - * prism2mgmt_mibset_mibget 215 - * 216 - * Set the value of a mib item. 217 - * 218 - * Arguments: 219 - * wlandev wlan device structure 220 - * msgp ptr to msg buffer 221 - * 222 - * Returns: 223 - * 0 success and done 224 - * <0 success, but we're waiting for something to finish. 225 - * >0 an error occurred while handling the message. 226 - * Side effects: 227 - * 228 - * Call context: 229 - * process thread (usually) 230 - * interrupt 231 - */ 232 - 233 - int prism2mgmt_mibset_mibget(struct wlandevice *wlandev, void *msgp) 234 - { 235 - struct hfa384x *hw = wlandev->priv; 236 - int result, isget; 237 - struct mibrec *mib; 238 - 239 - u16 which; 240 - 241 - struct p80211msg_dot11req_mibset *msg = msgp; 242 - struct p80211itemd *mibitem; 243 - 244 - msg->resultcode.status = P80211ENUM_msgitem_status_data_ok; 245 - msg->resultcode.data = P80211ENUM_resultcode_success; 246 - 247 - /* 248 - ** Determine if this is an Access Point or a station. 249 - */ 250 - 251 - which = F_STA; 252 - 253 - /* 254 - ** Find the MIB in the MIB table. Note that a MIB may be in the 255 - ** table twice...once for an AP and once for a station. Make sure 256 - ** to get the correct one. Note that DID=0 marks the end of the 257 - ** MIB table. 258 - */ 259 - 260 - mibitem = (struct p80211itemd *)msg->mibattribute.data; 261 - 262 - for (mib = mibtab; mib->did != 0; mib++) 263 - if (mib->did == mibitem->did && (mib->flag & which)) 264 - break; 265 - 266 - if (mib->did == 0) { 267 - msg->resultcode.data = P80211ENUM_resultcode_not_supported; 268 - goto done; 269 - } 270 - 271 - /* 272 - ** Determine if this is a "mibget" or a "mibset". If this is a 273 - ** "mibget", then make sure that the MIB may be read. Otherwise, 274 - ** this is a "mibset" so make sure that the MIB may be written. 275 - */ 276 - 277 - isget = (msg->msgcode == DIDMSG_DOT11REQ_MIBGET); 278 - 279 - if (isget) { 280 - if (!(mib->flag & F_READ)) { 281 - msg->resultcode.data = 282 - P80211ENUM_resultcode_cant_get_writeonly_mib; 283 - goto done; 284 - } 285 - } else { 286 - if (!(mib->flag & F_WRITE)) { 287 - msg->resultcode.data = 288 - P80211ENUM_resultcode_cant_set_readonly_mib; 289 - goto done; 290 - } 291 - } 292 - 293 - /* 294 - ** Execute the MIB function. If things worked okay, then make 295 - ** sure that the MIB function also worked okay. If so, and this 296 - ** is a "mibget", then the status value must be set for both the 297 - ** "mibattribute" parameter and the mib item within the data 298 - ** portion of the "mibattribute". 299 - */ 300 - 301 - result = mib->func(mib, isget, wlandev, hw, msg, (void *)mibitem->data); 302 - 303 - if (msg->resultcode.data == P80211ENUM_resultcode_success) { 304 - if (result != 0) { 305 - pr_debug("get/set failure, result=%d\n", result); 306 - msg->resultcode.data = 307 - P80211ENUM_resultcode_implementation_failure; 308 - } else { 309 - if (isget) { 310 - msg->mibattribute.status = 311 - P80211ENUM_msgitem_status_data_ok; 312 - mibitem->status = 313 - P80211ENUM_msgitem_status_data_ok; 314 - } 315 - } 316 - } 317 - 318 - done: 319 - return 0; 320 - } 321 - 322 - /* 323 - * prism2mib_bytearea2pstr 324 - * 325 - * Get/set pstr data to/from a byte area. 326 - * 327 - * MIB record parameters: 328 - * parm1 Prism2 RID value. 329 - * parm2 Number of bytes of RID data. 330 - * parm3 Not used. 331 - * 332 - * Arguments: 333 - * mib MIB record. 334 - * isget MIBGET/MIBSET flag. 335 - * wlandev wlan device structure. 336 - * priv "priv" structure. 337 - * hw "hw" structure. 338 - * msg Message structure. 339 - * data Data buffer. 340 - * 341 - * Returns: 342 - * 0 - Success. 343 - * ~0 - Error. 344 - * 345 - */ 346 - 347 - static int prism2mib_bytearea2pstr(struct mibrec *mib, 348 - int isget, 349 - struct wlandevice *wlandev, 350 - struct hfa384x *hw, 351 - struct p80211msg_dot11req_mibset *msg, 352 - void *data) 353 - { 354 - int result; 355 - struct p80211pstrd *pstr = data; 356 - u8 bytebuf[MIB_TMP_MAXLEN]; 357 - 358 - if (isget) { 359 - result = 360 - hfa384x_drvr_getconfig(hw, mib->parm1, bytebuf, mib->parm2); 361 - prism2mgmt_bytearea2pstr(bytebuf, pstr, mib->parm2); 362 - } else { 363 - memset(bytebuf, 0, mib->parm2); 364 - memcpy(bytebuf, pstr->data, pstr->len); 365 - result = 366 - hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, mib->parm2); 367 - } 368 - 369 - return result; 370 - } 371 - 372 - /* 373 - * prism2mib_uint32 374 - * 375 - * Get/set uint32 data. 376 - * 377 - * MIB record parameters: 378 - * parm1 Prism2 RID value. 379 - * parm2 Not used. 380 - * parm3 Not used. 381 - * 382 - * Arguments: 383 - * mib MIB record. 384 - * isget MIBGET/MIBSET flag. 385 - * wlandev wlan device structure. 386 - * priv "priv" structure. 387 - * hw "hw" structure. 388 - * msg Message structure. 389 - * data Data buffer. 390 - * 391 - * Returns: 392 - * 0 - Success. 393 - * ~0 - Error. 394 - * 395 - */ 396 - 397 - static int prism2mib_uint32(struct mibrec *mib, 398 - int isget, 399 - struct wlandevice *wlandev, 400 - struct hfa384x *hw, 401 - struct p80211msg_dot11req_mibset *msg, void *data) 402 - { 403 - int result; 404 - u32 *uint32 = data; 405 - u8 bytebuf[MIB_TMP_MAXLEN]; 406 - u16 *wordbuf = (u16 *)bytebuf; 407 - 408 - if (isget) { 409 - result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf); 410 - *uint32 = *wordbuf; 411 - } else { 412 - *wordbuf = *uint32; 413 - result = hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf); 414 - } 415 - 416 - return result; 417 - } 418 - 419 - /* 420 - * prism2mib_flag 421 - * 422 - * Get/set a flag. 423 - * 424 - * MIB record parameters: 425 - * parm1 Prism2 RID value. 426 - * parm2 Bit to get/set. 427 - * parm3 Not used. 428 - * 429 - * Arguments: 430 - * mib MIB record. 431 - * isget MIBGET/MIBSET flag. 432 - * wlandev wlan device structure. 433 - * priv "priv" structure. 434 - * hw "hw" structure. 435 - * msg Message structure. 436 - * data Data buffer. 437 - * 438 - * Returns: 439 - * 0 - Success. 440 - * ~0 - Error. 441 - * 442 - */ 443 - 444 - static int prism2mib_flag(struct mibrec *mib, 445 - int isget, 446 - struct wlandevice *wlandev, 447 - struct hfa384x *hw, 448 - struct p80211msg_dot11req_mibset *msg, void *data) 449 - { 450 - int result; 451 - u32 *uint32 = data; 452 - u8 bytebuf[MIB_TMP_MAXLEN]; 453 - u16 *wordbuf = (u16 *)bytebuf; 454 - u32 flags; 455 - 456 - result = hfa384x_drvr_getconfig16(hw, mib->parm1, wordbuf); 457 - if (result == 0) { 458 - flags = *wordbuf; 459 - if (isget) { 460 - *uint32 = (flags & mib->parm2) ? 461 - P80211ENUM_truth_true : P80211ENUM_truth_false; 462 - } else { 463 - if ((*uint32) == P80211ENUM_truth_true) 464 - flags |= mib->parm2; 465 - else 466 - flags &= ~mib->parm2; 467 - *wordbuf = flags; 468 - result = 469 - hfa384x_drvr_setconfig16(hw, mib->parm1, *wordbuf); 470 - } 471 - } 472 - 473 - return result; 474 - } 475 - 476 - /* 477 - * prism2mib_wepdefaultkey 478 - * 479 - * Get/set WEP default keys. 480 - * 481 - * MIB record parameters: 482 - * parm1 Prism2 RID value. 483 - * parm2 Number of bytes of RID data. 484 - * parm3 Not used. 485 - * 486 - * Arguments: 487 - * mib MIB record. 488 - * isget MIBGET/MIBSET flag. 489 - * wlandev wlan device structure. 490 - * priv "priv" structure. 491 - * hw "hw" structure. 492 - * msg Message structure. 493 - * data Data buffer. 494 - * 495 - * Returns: 496 - * 0 - Success. 497 - * ~0 - Error. 498 - * 499 - */ 500 - 501 - static int prism2mib_wepdefaultkey(struct mibrec *mib, 502 - int isget, 503 - struct wlandevice *wlandev, 504 - struct hfa384x *hw, 505 - struct p80211msg_dot11req_mibset *msg, 506 - void *data) 507 - { 508 - int result; 509 - struct p80211pstrd *pstr = data; 510 - u8 bytebuf[MIB_TMP_MAXLEN]; 511 - u16 len; 512 - 513 - if (isget) { 514 - result = 0; /* Should never happen. */ 515 - } else { 516 - len = (pstr->len > 5) ? HFA384x_RID_CNFWEP128DEFAULTKEY_LEN : 517 - HFA384x_RID_CNFWEPDEFAULTKEY_LEN; 518 - memset(bytebuf, 0, len); 519 - memcpy(bytebuf, pstr->data, pstr->len); 520 - result = hfa384x_drvr_setconfig(hw, mib->parm1, bytebuf, len); 521 - } 522 - 523 - return result; 524 - } 525 - 526 - /* 527 - * prism2mib_privacyinvoked 528 - * 529 - * Get/set the dot11PrivacyInvoked value. 530 - * 531 - * MIB record parameters: 532 - * parm1 Prism2 RID value. 533 - * parm2 Bit value for PrivacyInvoked flag. 534 - * parm3 Not used. 535 - * 536 - * Arguments: 537 - * mib MIB record. 538 - * isget MIBGET/MIBSET flag. 539 - * wlandev wlan device structure. 540 - * priv "priv" structure. 541 - * hw "hw" structure. 542 - * msg Message structure. 543 - * data Data buffer. 544 - * 545 - * Returns: 546 - * 0 - Success. 547 - * ~0 - Error. 548 - * 549 - */ 550 - 551 - static int prism2mib_privacyinvoked(struct mibrec *mib, 552 - int isget, 553 - struct wlandevice *wlandev, 554 - struct hfa384x *hw, 555 - struct p80211msg_dot11req_mibset *msg, 556 - void *data) 557 - { 558 - if (wlandev->hostwep & HOSTWEP_DECRYPT) { 559 - if (wlandev->hostwep & HOSTWEP_DECRYPT) 560 - mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_RXCRYPT; 561 - if (wlandev->hostwep & HOSTWEP_ENCRYPT) 562 - mib->parm2 |= HFA384x_WEPFLAGS_DISABLE_TXCRYPT; 563 - } 564 - 565 - return prism2mib_flag(mib, isget, wlandev, hw, msg, data); 566 - } 567 - 568 - /* 569 - * prism2mib_fragmentationthreshold 570 - * 571 - * Get/set the fragmentation threshold. 572 - * 573 - * MIB record parameters: 574 - * parm1 Prism2 RID value. 575 - * parm2 Not used. 576 - * parm3 Not used. 577 - * 578 - * Arguments: 579 - * mib MIB record. 580 - * isget MIBGET/MIBSET flag. 581 - * wlandev wlan device structure. 582 - * priv "priv" structure. 583 - * hw "hw" structure. 584 - * msg Message structure. 585 - * data Data buffer. 586 - * 587 - * Returns: 588 - * 0 - Success. 589 - * ~0 - Error. 590 - * 591 - */ 592 - 593 - static int 594 - prism2mib_fragmentationthreshold(struct mibrec *mib, 595 - int isget, 596 - struct wlandevice *wlandev, 597 - struct hfa384x *hw, 598 - struct p80211msg_dot11req_mibset *msg, 599 - void *data) 600 - { 601 - u32 *uint32 = data; 602 - 603 - if (!isget) 604 - if ((*uint32) % 2) { 605 - netdev_warn(wlandev->netdev, 606 - "Attempt to set odd number FragmentationThreshold\n"); 607 - msg->resultcode.data = 608 - P80211ENUM_resultcode_not_supported; 609 - return 0; 610 - } 611 - 612 - return prism2mib_uint32(mib, isget, wlandev, hw, msg, data); 613 - } 614 - 615 - /* 616 - * prism2mib_priv 617 - * 618 - * Get/set values in the "priv" data structure. 619 - * 620 - * MIB record parameters: 621 - * parm1 Not used. 622 - * parm2 Not used. 623 - * parm3 Not used. 624 - * 625 - * Arguments: 626 - * mib MIB record. 627 - * isget MIBGET/MIBSET flag. 628 - * wlandev wlan device structure. 629 - * priv "priv" structure. 630 - * hw "hw" structure. 631 - * msg Message structure. 632 - * data Data buffer. 633 - * 634 - * Returns: 635 - * 0 - Success. 636 - * ~0 - Error. 637 - * 638 - */ 639 - 640 - static int prism2mib_priv(struct mibrec *mib, 641 - int isget, 642 - struct wlandevice *wlandev, 643 - struct hfa384x *hw, 644 - struct p80211msg_dot11req_mibset *msg, void *data) 645 - { 646 - struct p80211pstrd *pstr = data; 647 - 648 - switch (mib->did) { 649 - case DIDMIB_LNX_CONFIGTABLE_RSNAIE: { 650 - /* 651 - * This can never work: wpa is on the stack 652 - * and has no bytes allocated in wpa.data. 653 - */ 654 - struct hfa384x_wpa_data wpa; 655 - 656 - if (isget) { 657 - hfa384x_drvr_getconfig(hw, 658 - HFA384x_RID_CNFWPADATA, 659 - (u8 *)&wpa, 660 - sizeof(wpa)); 661 - pstr->len = 0; 662 - } else { 663 - wpa.datalen = 0; 664 - 665 - hfa384x_drvr_setconfig(hw, 666 - HFA384x_RID_CNFWPADATA, 667 - (u8 *)&wpa, 668 - sizeof(wpa)); 669 - } 670 - break; 671 - } 672 - default: 673 - netdev_err(wlandev->netdev, "Unhandled DID 0x%08x\n", mib->did); 674 - } 675 - 676 - return 0; 677 - } 678 - 679 - /* 680 - * prism2mgmt_pstr2bytestr 681 - * 682 - * Convert the pstr data in the WLAN message structure into an hfa384x 683 - * byte string format. 684 - * 685 - * Arguments: 686 - * bytestr hfa384x byte string data type 687 - * pstr wlan message data 688 - * 689 - * Returns: 690 - * Nothing 691 - * 692 - */ 693 - 694 - void prism2mgmt_pstr2bytestr(struct hfa384x_bytestr *bytestr, 695 - struct p80211pstrd *pstr) 696 - { 697 - bytestr->len = cpu_to_le16((u16)(pstr->len)); 698 - memcpy(bytestr->data, pstr->data, pstr->len); 699 - } 700 - 701 - /* 702 - * prism2mgmt_bytestr2pstr 703 - * 704 - * Convert the data in an hfa384x byte string format into a 705 - * pstr in the WLAN message. 706 - * 707 - * Arguments: 708 - * bytestr hfa384x byte string data type 709 - * msg wlan message 710 - * 711 - * Returns: 712 - * Nothing 713 - * 714 - */ 715 - 716 - void prism2mgmt_bytestr2pstr(struct hfa384x_bytestr *bytestr, 717 - struct p80211pstrd *pstr) 718 - { 719 - pstr->len = (u8)(le16_to_cpu(bytestr->len)); 720 - memcpy(pstr->data, bytestr->data, pstr->len); 721 - } 722 - 723 - /* 724 - * prism2mgmt_bytearea2pstr 725 - * 726 - * Convert the data in an hfa384x byte area format into a pstr 727 - * in the WLAN message. 728 - * 729 - * Arguments: 730 - * bytearea hfa384x byte area data type 731 - * msg wlan message 732 - * 733 - * Returns: 734 - * Nothing 735 - * 736 - */ 737 - 738 - void prism2mgmt_bytearea2pstr(u8 *bytearea, struct p80211pstrd *pstr, int len) 739 - { 740 - pstr->len = (u8)len; 741 - memcpy(pstr->data, bytearea, len); 742 - }
-1945
drivers/staging/wlan-ng/prism2sta.c
··· 1 - // SPDX-License-Identifier: (GPL-2.0 OR MPL-1.1) 2 - /* 3 - * 4 - * Implements the station functionality for prism2 5 - * 6 - * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved. 7 - * -------------------------------------------------------------------- 8 - * 9 - * linux-wlan 10 - * 11 - * -------------------------------------------------------------------- 12 - * 13 - * Inquiries regarding the linux-wlan Open Source project can be 14 - * made directly to: 15 - * 16 - * AbsoluteValue Systems Inc. 17 - * info@linux-wlan.com 18 - * http://www.linux-wlan.com 19 - * 20 - * -------------------------------------------------------------------- 21 - * 22 - * Portions of the development of this software were funded by 23 - * Intersil Corporation as part of PRISM(R) chipset product development. 24 - * 25 - * -------------------------------------------------------------------- 26 - * 27 - * This file implements the module and linux pcmcia routines for the 28 - * prism2 driver. 29 - * 30 - * -------------------------------------------------------------------- 31 - */ 32 - 33 - #include <linux/module.h> 34 - #include <linux/kernel.h> 35 - #include <linux/sched.h> 36 - #include <linux/types.h> 37 - #include <linux/slab.h> 38 - #include <linux/wireless.h> 39 - #include <linux/netdevice.h> 40 - #include <linux/workqueue.h> 41 - #include <linux/byteorder/generic.h> 42 - #include <linux/etherdevice.h> 43 - 44 - #include <linux/io.h> 45 - #include <linux/delay.h> 46 - #include <asm/byteorder.h> 47 - #include <linux/if_arp.h> 48 - #include <linux/if_ether.h> 49 - #include <linux/bitops.h> 50 - 51 - #include "p80211types.h" 52 - #include "p80211hdr.h" 53 - #include "p80211mgmt.h" 54 - #include "p80211conv.h" 55 - #include "p80211msg.h" 56 - #include "p80211netdev.h" 57 - #include "p80211req.h" 58 - #include "p80211metadef.h" 59 - #include "p80211metastruct.h" 60 - #include "hfa384x.h" 61 - #include "prism2mgmt.h" 62 - 63 - static char *dev_info = "prism2_usb"; 64 - static struct wlandevice *create_wlan(void); 65 - 66 - int prism2_reset_holdtime = 30; /* Reset hold time in ms */ 67 - int prism2_reset_settletime = 100; /* Reset settle time in ms */ 68 - 69 - static int prism2_doreset; /* Do a reset at init? */ 70 - 71 - module_param(prism2_doreset, int, 0644); 72 - MODULE_PARM_DESC(prism2_doreset, "Issue a reset on initialization"); 73 - 74 - module_param(prism2_reset_holdtime, int, 0644); 75 - MODULE_PARM_DESC(prism2_reset_holdtime, "reset hold time in ms"); 76 - module_param(prism2_reset_settletime, int, 0644); 77 - MODULE_PARM_DESC(prism2_reset_settletime, "reset settle time in ms"); 78 - 79 - MODULE_LICENSE("Dual MPL/GPL"); 80 - 81 - static int prism2sta_open(struct wlandevice *wlandev); 82 - static int prism2sta_close(struct wlandevice *wlandev); 83 - static void prism2sta_reset(struct wlandevice *wlandev); 84 - static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb, 85 - struct p80211_hdr *p80211_hdr, 86 - struct p80211_metawep *p80211_wep); 87 - static int prism2sta_mlmerequest(struct wlandevice *wlandev, 88 - struct p80211msg *msg); 89 - static int prism2sta_getcardinfo(struct wlandevice *wlandev); 90 - static int prism2sta_globalsetup(struct wlandevice *wlandev); 91 - static int prism2sta_setmulticast(struct wlandevice *wlandev, 92 - struct net_device *dev); 93 - static void prism2sta_inf_tallies(struct wlandevice *wlandev, 94 - struct hfa384x_inf_frame *inf); 95 - static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev, 96 - struct hfa384x_inf_frame *inf); 97 - static void prism2sta_inf_scanresults(struct wlandevice *wlandev, 98 - struct hfa384x_inf_frame *inf); 99 - static void prism2sta_inf_chinforesults(struct wlandevice *wlandev, 100 - struct hfa384x_inf_frame *inf); 101 - static void prism2sta_inf_linkstatus(struct wlandevice *wlandev, 102 - struct hfa384x_inf_frame *inf); 103 - static void prism2sta_inf_assocstatus(struct wlandevice *wlandev, 104 - struct hfa384x_inf_frame *inf); 105 - static void prism2sta_inf_authreq(struct wlandevice *wlandev, 106 - struct hfa384x_inf_frame *inf); 107 - static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev, 108 - struct hfa384x_inf_frame *inf); 109 - static void prism2sta_inf_psusercnt(struct wlandevice *wlandev, 110 - struct hfa384x_inf_frame *inf); 111 - 112 - /* 113 - * prism2sta_open 114 - * 115 - * WLAN device open method. Called from p80211netdev when kernel 116 - * device open (start) method is called in response to the 117 - * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP 118 - * from clear to set. 119 - * 120 - * Arguments: 121 - * wlandev wlan device structure 122 - * 123 - * Returns: 124 - * 0 success 125 - * >0 f/w reported error 126 - * <0 driver reported error 127 - * 128 - * Side effects: 129 - * 130 - * Call context: 131 - * process thread 132 - */ 133 - static int prism2sta_open(struct wlandevice *wlandev) 134 - { 135 - /* We don't currently have to do anything else. 136 - * The setup of the MAC should be subsequently completed via 137 - * the mlme commands. 138 - * Higher layers know we're ready from dev->start==1 and 139 - * dev->tbusy==0. Our rx path knows to pass up received/ 140 - * frames because of dev->flags&IFF_UP is true. 141 - */ 142 - 143 - return 0; 144 - } 145 - 146 - /* 147 - * prism2sta_close 148 - * 149 - * WLAN device close method. Called from p80211netdev when kernel 150 - * device close method is called in response to the 151 - * SIOCSIIFFLAGS ioctl changing the flags bit IFF_UP 152 - * from set to clear. 153 - * 154 - * Arguments: 155 - * wlandev wlan device structure 156 - * 157 - * Returns: 158 - * 0 success 159 - * >0 f/w reported error 160 - * <0 driver reported error 161 - * 162 - * Side effects: 163 - * 164 - * Call context: 165 - * process thread 166 - */ 167 - static int prism2sta_close(struct wlandevice *wlandev) 168 - { 169 - /* We don't currently have to do anything else. 170 - * Higher layers know we're not ready from dev->start==0 and 171 - * dev->tbusy==1. Our rx path knows to not pass up received 172 - * frames because of dev->flags&IFF_UP is false. 173 - */ 174 - 175 - return 0; 176 - } 177 - 178 - /* 179 - * prism2sta_reset 180 - * 181 - * Currently not implemented. 182 - * 183 - * Arguments: 184 - * wlandev wlan device structure 185 - * none 186 - * 187 - * Returns: 188 - * nothing 189 - * 190 - * Side effects: 191 - * 192 - * Call context: 193 - * process thread 194 - */ 195 - static void prism2sta_reset(struct wlandevice *wlandev) 196 - { 197 - } 198 - 199 - /* 200 - * prism2sta_txframe 201 - * 202 - * Takes a frame from p80211 and queues it for transmission. 203 - * 204 - * Arguments: 205 - * wlandev wlan device structure 206 - * pb packet buffer struct. Contains an 802.11 207 - * data frame. 208 - * p80211_hdr points to the 802.11 header for the packet. 209 - * Returns: 210 - * 0 Success and more buffs available 211 - * 1 Success but no more buffs 212 - * 2 Allocation failure 213 - * 4 Buffer full or queue busy 214 - * 215 - * Side effects: 216 - * 217 - * Call context: 218 - * process thread 219 - */ 220 - static int prism2sta_txframe(struct wlandevice *wlandev, struct sk_buff *skb, 221 - struct p80211_hdr *p80211_hdr, 222 - struct p80211_metawep *p80211_wep) 223 - { 224 - struct hfa384x *hw = wlandev->priv; 225 - 226 - /* If necessary, set the 802.11 WEP bit */ 227 - if ((wlandev->hostwep & (HOSTWEP_PRIVACYINVOKED | HOSTWEP_ENCRYPT)) == 228 - HOSTWEP_PRIVACYINVOKED) { 229 - p80211_hdr->frame_control |= cpu_to_le16(WLAN_SET_FC_ISWEP(1)); 230 - } 231 - 232 - return hfa384x_drvr_txframe(hw, skb, p80211_hdr, p80211_wep); 233 - } 234 - 235 - /* 236 - * prism2sta_mlmerequest 237 - * 238 - * wlan command message handler. All we do here is pass the message 239 - * over to the prism2sta_mgmt_handler. 240 - * 241 - * Arguments: 242 - * wlandev wlan device structure 243 - * msg wlan command message 244 - * Returns: 245 - * 0 success 246 - * <0 successful acceptance of message, but we're 247 - * waiting for an async process to finish before 248 - * we're done with the msg. When the asynch 249 - * process is done, we'll call the p80211 250 - * function p80211req_confirm() . 251 - * >0 An error occurred while we were handling 252 - * the message. 253 - * 254 - * Side effects: 255 - * 256 - * Call context: 257 - * process thread 258 - */ 259 - static int prism2sta_mlmerequest(struct wlandevice *wlandev, 260 - struct p80211msg *msg) 261 - { 262 - struct hfa384x *hw = wlandev->priv; 263 - 264 - int result = 0; 265 - 266 - switch (msg->msgcode) { 267 - case DIDMSG_DOT11REQ_MIBGET: 268 - netdev_dbg(wlandev->netdev, "Received mibget request\n"); 269 - result = prism2mgmt_mibset_mibget(wlandev, msg); 270 - break; 271 - case DIDMSG_DOT11REQ_MIBSET: 272 - netdev_dbg(wlandev->netdev, "Received mibset request\n"); 273 - result = prism2mgmt_mibset_mibget(wlandev, msg); 274 - break; 275 - case DIDMSG_DOT11REQ_SCAN: 276 - netdev_dbg(wlandev->netdev, "Received scan request\n"); 277 - result = prism2mgmt_scan(wlandev, msg); 278 - break; 279 - case DIDMSG_DOT11REQ_SCAN_RESULTS: 280 - netdev_dbg(wlandev->netdev, "Received scan_results request\n"); 281 - result = prism2mgmt_scan_results(wlandev, msg); 282 - break; 283 - case DIDMSG_DOT11REQ_START: 284 - netdev_dbg(wlandev->netdev, "Received mlme start request\n"); 285 - result = prism2mgmt_start(wlandev, msg); 286 - break; 287 - /* 288 - * Prism2 specific messages 289 - */ 290 - case DIDMSG_P2REQ_READPDA: 291 - netdev_dbg(wlandev->netdev, "Received mlme readpda request\n"); 292 - result = prism2mgmt_readpda(wlandev, msg); 293 - break; 294 - case DIDMSG_P2REQ_RAMDL_STATE: 295 - netdev_dbg(wlandev->netdev, 296 - "Received mlme ramdl_state request\n"); 297 - result = prism2mgmt_ramdl_state(wlandev, msg); 298 - break; 299 - case DIDMSG_P2REQ_RAMDL_WRITE: 300 - netdev_dbg(wlandev->netdev, 301 - "Received mlme ramdl_write request\n"); 302 - result = prism2mgmt_ramdl_write(wlandev, msg); 303 - break; 304 - case DIDMSG_P2REQ_FLASHDL_STATE: 305 - netdev_dbg(wlandev->netdev, 306 - "Received mlme flashdl_state request\n"); 307 - result = prism2mgmt_flashdl_state(wlandev, msg); 308 - break; 309 - case DIDMSG_P2REQ_FLASHDL_WRITE: 310 - netdev_dbg(wlandev->netdev, 311 - "Received mlme flashdl_write request\n"); 312 - result = prism2mgmt_flashdl_write(wlandev, msg); 313 - break; 314 - /* 315 - * Linux specific messages 316 - */ 317 - case DIDMSG_LNXREQ_HOSTWEP: 318 - break; /* ignore me. */ 319 - case DIDMSG_LNXREQ_IFSTATE: { 320 - struct p80211msg_lnxreq_ifstate *ifstatemsg; 321 - 322 - netdev_dbg(wlandev->netdev, "Received mlme ifstate request\n"); 323 - ifstatemsg = (struct p80211msg_lnxreq_ifstate *)msg; 324 - result = prism2sta_ifstate(wlandev, 325 - ifstatemsg->ifstate.data); 326 - ifstatemsg->resultcode.status = 327 - P80211ENUM_msgitem_status_data_ok; 328 - ifstatemsg->resultcode.data = result; 329 - result = 0; 330 - break; 331 - } 332 - case DIDMSG_LNXREQ_WLANSNIFF: 333 - netdev_dbg(wlandev->netdev, 334 - "Received mlme wlansniff request\n"); 335 - result = prism2mgmt_wlansniff(wlandev, msg); 336 - break; 337 - case DIDMSG_LNXREQ_AUTOJOIN: 338 - netdev_dbg(wlandev->netdev, "Received mlme autojoin request\n"); 339 - result = prism2mgmt_autojoin(wlandev, msg); 340 - break; 341 - case DIDMSG_LNXREQ_COMMSQUALITY: { 342 - struct p80211msg_lnxreq_commsquality *qualmsg; 343 - 344 - netdev_dbg(wlandev->netdev, "Received commsquality request\n"); 345 - 346 - qualmsg = (struct p80211msg_lnxreq_commsquality *)msg; 347 - 348 - qualmsg->link.status = P80211ENUM_msgitem_status_data_ok; 349 - qualmsg->level.status = P80211ENUM_msgitem_status_data_ok; 350 - qualmsg->noise.status = P80211ENUM_msgitem_status_data_ok; 351 - 352 - qualmsg->link.data = le16_to_cpu(hw->qual.cq_curr_bss); 353 - qualmsg->level.data = le16_to_cpu(hw->qual.asl_curr_bss); 354 - qualmsg->noise.data = le16_to_cpu(hw->qual.anl_curr_fc); 355 - qualmsg->txrate.data = hw->txrate; 356 - 357 - break; 358 - } 359 - default: 360 - netdev_warn(wlandev->netdev, 361 - "Unknown mgmt request message 0x%08x", 362 - msg->msgcode); 363 - break; 364 - } 365 - 366 - return result; 367 - } 368 - 369 - /* 370 - * prism2sta_ifstate 371 - * 372 - * Interface state. This is the primary WLAN interface enable/disable 373 - * handler. Following the driver/load/deviceprobe sequence, this 374 - * function must be called with a state of "enable" before any other 375 - * commands will be accepted. 376 - * 377 - * Arguments: 378 - * wlandev wlan device structure 379 - * msgp ptr to msg buffer 380 - * 381 - * Returns: 382 - * A p80211 message resultcode value. 383 - * 384 - * Side effects: 385 - * 386 - * Call context: 387 - * process thread (usually) 388 - * interrupt 389 - */ 390 - u32 prism2sta_ifstate(struct wlandevice *wlandev, u32 ifstate) 391 - { 392 - struct hfa384x *hw = wlandev->priv; 393 - u32 result; 394 - 395 - result = P80211ENUM_resultcode_implementation_failure; 396 - 397 - netdev_dbg(wlandev->netdev, "Current MSD state(%d), requesting(%d)\n", 398 - wlandev->msdstate, ifstate); 399 - switch (ifstate) { 400 - case P80211ENUM_ifstate_fwload: 401 - switch (wlandev->msdstate) { 402 - case WLAN_MSD_HWPRESENT: 403 - wlandev->msdstate = WLAN_MSD_FWLOAD_PENDING; 404 - /* 405 - * Initialize the device+driver sufficiently 406 - * for firmware loading. 407 - */ 408 - result = hfa384x_drvr_start(hw); 409 - if (result) { 410 - netdev_err(wlandev->netdev, 411 - "hfa384x_drvr_start() failed,result=%d\n", 412 - (int)result); 413 - result = 414 - P80211ENUM_resultcode_implementation_failure; 415 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 416 - break; 417 - } 418 - wlandev->msdstate = WLAN_MSD_FWLOAD; 419 - result = P80211ENUM_resultcode_success; 420 - break; 421 - case WLAN_MSD_FWLOAD: 422 - hfa384x_cmd_initialize(hw); 423 - result = P80211ENUM_resultcode_success; 424 - break; 425 - case WLAN_MSD_RUNNING: 426 - netdev_warn(wlandev->netdev, 427 - "Cannot enter fwload state from enable state, you must disable first.\n"); 428 - result = P80211ENUM_resultcode_invalid_parameters; 429 - break; 430 - case WLAN_MSD_HWFAIL: 431 - default: 432 - /* probe() had a problem or the msdstate contains 433 - * an unrecognized value, there's nothing we can do. 434 - */ 435 - result = P80211ENUM_resultcode_implementation_failure; 436 - break; 437 - } 438 - break; 439 - case P80211ENUM_ifstate_enable: 440 - switch (wlandev->msdstate) { 441 - case WLAN_MSD_HWPRESENT: 442 - case WLAN_MSD_FWLOAD: 443 - wlandev->msdstate = WLAN_MSD_RUNNING_PENDING; 444 - /* Initialize the device+driver for full 445 - * operation. Note that this might me an FWLOAD 446 - * to RUNNING transition so we must not do a chip 447 - * or board level reset. Note that on failure, 448 - * the MSD state is set to HWPRESENT because we 449 - * can't make any assumptions about the state 450 - * of the hardware or a previous firmware load. 451 - */ 452 - result = hfa384x_drvr_start(hw); 453 - if (result) { 454 - netdev_err(wlandev->netdev, 455 - "hfa384x_drvr_start() failed,result=%d\n", 456 - (int)result); 457 - result = 458 - P80211ENUM_resultcode_implementation_failure; 459 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 460 - break; 461 - } 462 - 463 - result = prism2sta_getcardinfo(wlandev); 464 - if (result) { 465 - netdev_err(wlandev->netdev, 466 - "prism2sta_getcardinfo() failed,result=%d\n", 467 - (int)result); 468 - result = 469 - P80211ENUM_resultcode_implementation_failure; 470 - hfa384x_drvr_stop(hw); 471 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 472 - break; 473 - } 474 - result = prism2sta_globalsetup(wlandev); 475 - if (result) { 476 - netdev_err(wlandev->netdev, 477 - "prism2sta_globalsetup() failed,result=%d\n", 478 - (int)result); 479 - result = 480 - P80211ENUM_resultcode_implementation_failure; 481 - hfa384x_drvr_stop(hw); 482 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 483 - break; 484 - } 485 - wlandev->msdstate = WLAN_MSD_RUNNING; 486 - hw->join_ap = 0; 487 - hw->join_retries = 60; 488 - result = P80211ENUM_resultcode_success; 489 - break; 490 - case WLAN_MSD_RUNNING: 491 - /* Do nothing, we're already in this state. */ 492 - result = P80211ENUM_resultcode_success; 493 - break; 494 - case WLAN_MSD_HWFAIL: 495 - default: 496 - /* probe() had a problem or the msdstate contains 497 - * an unrecognized value, there's nothing we can do. 498 - */ 499 - result = P80211ENUM_resultcode_implementation_failure; 500 - break; 501 - } 502 - break; 503 - case P80211ENUM_ifstate_disable: 504 - switch (wlandev->msdstate) { 505 - case WLAN_MSD_HWPRESENT: 506 - /* Do nothing, we're already in this state. */ 507 - result = P80211ENUM_resultcode_success; 508 - break; 509 - case WLAN_MSD_FWLOAD: 510 - case WLAN_MSD_RUNNING: 511 - wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING; 512 - /* 513 - * TODO: Shut down the MAC completely. Here a chip 514 - * or board level reset is probably called for. 515 - * After a "disable" _all_ results are lost, even 516 - * those from a fwload. 517 - */ 518 - if (!wlandev->hwremoved) 519 - netif_carrier_off(wlandev->netdev); 520 - 521 - hfa384x_drvr_stop(hw); 522 - 523 - wlandev->macmode = WLAN_MACMODE_NONE; 524 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 525 - result = P80211ENUM_resultcode_success; 526 - break; 527 - case WLAN_MSD_HWFAIL: 528 - default: 529 - /* probe() had a problem or the msdstate contains 530 - * an unrecognized value, there's nothing we can do. 531 - */ 532 - result = P80211ENUM_resultcode_implementation_failure; 533 - break; 534 - } 535 - break; 536 - default: 537 - result = P80211ENUM_resultcode_invalid_parameters; 538 - break; 539 - } 540 - 541 - return result; 542 - } 543 - 544 - /* 545 - * prism2sta_getcardinfo 546 - * 547 - * Collect the NICID, firmware version and any other identifiers 548 - * we'd like to have in host-side data structures. 549 - * 550 - * Arguments: 551 - * wlandev wlan device structure 552 - * 553 - * Returns: 554 - * 0 success 555 - * >0 f/w reported error 556 - * <0 driver reported error 557 - * 558 - * Side effects: 559 - * 560 - * Call context: 561 - * Either. 562 - */ 563 - static int prism2sta_getcardinfo(struct wlandevice *wlandev) 564 - { 565 - int result = 0; 566 - struct hfa384x *hw = wlandev->priv; 567 - u16 temp; 568 - u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN]; 569 - u8 addr[ETH_ALEN]; 570 - 571 - /* Collect version and compatibility info */ 572 - /* Some are critical, some are not */ 573 - /* NIC identity */ 574 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICIDENTITY, 575 - &hw->ident_nic, 576 - sizeof(struct hfa384x_compident)); 577 - if (result) { 578 - netdev_err(wlandev->netdev, "Failed to retrieve NICIDENTITY\n"); 579 - goto failed; 580 - } 581 - 582 - /* get all the nic id fields in host byte order */ 583 - le16_to_cpus(&hw->ident_nic.id); 584 - le16_to_cpus(&hw->ident_nic.variant); 585 - le16_to_cpus(&hw->ident_nic.major); 586 - le16_to_cpus(&hw->ident_nic.minor); 587 - 588 - netdev_info(wlandev->netdev, "ident: nic h/w: id=0x%02x %d.%d.%d\n", 589 - hw->ident_nic.id, hw->ident_nic.major, 590 - hw->ident_nic.minor, hw->ident_nic.variant); 591 - 592 - /* Primary f/w identity */ 593 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRIIDENTITY, 594 - &hw->ident_pri_fw, 595 - sizeof(struct hfa384x_compident)); 596 - if (result) { 597 - netdev_err(wlandev->netdev, "Failed to retrieve PRIIDENTITY\n"); 598 - goto failed; 599 - } 600 - 601 - /* get all the private fw id fields in host byte order */ 602 - le16_to_cpus(&hw->ident_pri_fw.id); 603 - le16_to_cpus(&hw->ident_pri_fw.variant); 604 - le16_to_cpus(&hw->ident_pri_fw.major); 605 - le16_to_cpus(&hw->ident_pri_fw.minor); 606 - 607 - netdev_info(wlandev->netdev, "ident: pri f/w: id=0x%02x %d.%d.%d\n", 608 - hw->ident_pri_fw.id, hw->ident_pri_fw.major, 609 - hw->ident_pri_fw.minor, hw->ident_pri_fw.variant); 610 - 611 - /* Station (Secondary?) f/w identity */ 612 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STAIDENTITY, 613 - &hw->ident_sta_fw, 614 - sizeof(struct hfa384x_compident)); 615 - if (result) { 616 - netdev_err(wlandev->netdev, "Failed to retrieve STAIDENTITY\n"); 617 - goto failed; 618 - } 619 - 620 - if (hw->ident_nic.id < 0x8000) { 621 - netdev_err(wlandev->netdev, 622 - "FATAL: Card is not an Intersil Prism2/2.5/3\n"); 623 - result = -1; 624 - goto failed; 625 - } 626 - 627 - /* get all the station fw id fields in host byte order */ 628 - le16_to_cpus(&hw->ident_sta_fw.id); 629 - le16_to_cpus(&hw->ident_sta_fw.variant); 630 - le16_to_cpus(&hw->ident_sta_fw.major); 631 - le16_to_cpus(&hw->ident_sta_fw.minor); 632 - 633 - /* strip out the 'special' variant bits */ 634 - hw->mm_mods = hw->ident_sta_fw.variant & GENMASK(15, 14); 635 - hw->ident_sta_fw.variant &= ~((u16)GENMASK(15, 14)); 636 - 637 - if (hw->ident_sta_fw.id == 0x1f) { 638 - netdev_info(wlandev->netdev, 639 - "ident: sta f/w: id=0x%02x %d.%d.%d\n", 640 - hw->ident_sta_fw.id, hw->ident_sta_fw.major, 641 - hw->ident_sta_fw.minor, hw->ident_sta_fw.variant); 642 - } else { 643 - netdev_info(wlandev->netdev, 644 - "ident: ap f/w: id=0x%02x %d.%d.%d\n", 645 - hw->ident_sta_fw.id, hw->ident_sta_fw.major, 646 - hw->ident_sta_fw.minor, hw->ident_sta_fw.variant); 647 - netdev_err(wlandev->netdev, "Unsupported Tertiary AP firmware loaded!\n"); 648 - goto failed; 649 - } 650 - 651 - /* Compatibility range, Modem supplier */ 652 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_MFISUPRANGE, 653 - &hw->cap_sup_mfi, 654 - sizeof(struct hfa384x_caplevel)); 655 - if (result) { 656 - netdev_err(wlandev->netdev, "Failed to retrieve MFISUPRANGE\n"); 657 - goto failed; 658 - } 659 - 660 - /* get all the Compatibility range, modem interface supplier 661 - * fields in byte order 662 - */ 663 - le16_to_cpus(&hw->cap_sup_mfi.role); 664 - le16_to_cpus(&hw->cap_sup_mfi.id); 665 - le16_to_cpus(&hw->cap_sup_mfi.variant); 666 - le16_to_cpus(&hw->cap_sup_mfi.bottom); 667 - le16_to_cpus(&hw->cap_sup_mfi.top); 668 - 669 - netdev_info(wlandev->netdev, 670 - "MFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 671 - hw->cap_sup_mfi.role, hw->cap_sup_mfi.id, 672 - hw->cap_sup_mfi.variant, hw->cap_sup_mfi.bottom, 673 - hw->cap_sup_mfi.top); 674 - 675 - /* Compatibility range, Controller supplier */ 676 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CFISUPRANGE, 677 - &hw->cap_sup_cfi, 678 - sizeof(struct hfa384x_caplevel)); 679 - if (result) { 680 - netdev_err(wlandev->netdev, "Failed to retrieve CFISUPRANGE\n"); 681 - goto failed; 682 - } 683 - 684 - /* get all the Compatibility range, controller interface supplier 685 - * fields in byte order 686 - */ 687 - le16_to_cpus(&hw->cap_sup_cfi.role); 688 - le16_to_cpus(&hw->cap_sup_cfi.id); 689 - le16_to_cpus(&hw->cap_sup_cfi.variant); 690 - le16_to_cpus(&hw->cap_sup_cfi.bottom); 691 - le16_to_cpus(&hw->cap_sup_cfi.top); 692 - 693 - netdev_info(wlandev->netdev, 694 - "CFI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 695 - hw->cap_sup_cfi.role, hw->cap_sup_cfi.id, 696 - hw->cap_sup_cfi.variant, hw->cap_sup_cfi.bottom, 697 - hw->cap_sup_cfi.top); 698 - 699 - /* Compatibility range, Primary f/w supplier */ 700 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRISUPRANGE, 701 - &hw->cap_sup_pri, 702 - sizeof(struct hfa384x_caplevel)); 703 - if (result) { 704 - netdev_err(wlandev->netdev, "Failed to retrieve PRISUPRANGE\n"); 705 - goto failed; 706 - } 707 - 708 - /* get all the Compatibility range, primary firmware supplier 709 - * fields in byte order 710 - */ 711 - le16_to_cpus(&hw->cap_sup_pri.role); 712 - le16_to_cpus(&hw->cap_sup_pri.id); 713 - le16_to_cpus(&hw->cap_sup_pri.variant); 714 - le16_to_cpus(&hw->cap_sup_pri.bottom); 715 - le16_to_cpus(&hw->cap_sup_pri.top); 716 - 717 - netdev_info(wlandev->netdev, 718 - "PRI:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 719 - hw->cap_sup_pri.role, hw->cap_sup_pri.id, 720 - hw->cap_sup_pri.variant, hw->cap_sup_pri.bottom, 721 - hw->cap_sup_pri.top); 722 - 723 - /* Compatibility range, Station f/w supplier */ 724 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STASUPRANGE, 725 - &hw->cap_sup_sta, 726 - sizeof(struct hfa384x_caplevel)); 727 - if (result) { 728 - netdev_err(wlandev->netdev, "Failed to retrieve STASUPRANGE\n"); 729 - goto failed; 730 - } 731 - 732 - /* get all the Compatibility range, station firmware supplier 733 - * fields in byte order 734 - */ 735 - le16_to_cpus(&hw->cap_sup_sta.role); 736 - le16_to_cpus(&hw->cap_sup_sta.id); 737 - le16_to_cpus(&hw->cap_sup_sta.variant); 738 - le16_to_cpus(&hw->cap_sup_sta.bottom); 739 - le16_to_cpus(&hw->cap_sup_sta.top); 740 - 741 - if (hw->cap_sup_sta.id == 0x04) { 742 - netdev_info(wlandev->netdev, 743 - "STA:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 744 - hw->cap_sup_sta.role, hw->cap_sup_sta.id, 745 - hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom, 746 - hw->cap_sup_sta.top); 747 - } else { 748 - netdev_info(wlandev->netdev, 749 - "AP:SUP:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 750 - hw->cap_sup_sta.role, hw->cap_sup_sta.id, 751 - hw->cap_sup_sta.variant, hw->cap_sup_sta.bottom, 752 - hw->cap_sup_sta.top); 753 - } 754 - 755 - /* Compatibility range, primary f/w actor, CFI supplier */ 756 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_PRI_CFIACTRANGES, 757 - &hw->cap_act_pri_cfi, 758 - sizeof(struct hfa384x_caplevel)); 759 - if (result) { 760 - netdev_err(wlandev->netdev, "Failed to retrieve PRI_CFIACTRANGES\n"); 761 - goto failed; 762 - } 763 - 764 - /* get all the Compatibility range, primary f/w actor, CFI supplier 765 - * fields in byte order 766 - */ 767 - le16_to_cpus(&hw->cap_act_pri_cfi.role); 768 - le16_to_cpus(&hw->cap_act_pri_cfi.id); 769 - le16_to_cpus(&hw->cap_act_pri_cfi.variant); 770 - le16_to_cpus(&hw->cap_act_pri_cfi.bottom); 771 - le16_to_cpus(&hw->cap_act_pri_cfi.top); 772 - 773 - netdev_info(wlandev->netdev, 774 - "PRI-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 775 - hw->cap_act_pri_cfi.role, hw->cap_act_pri_cfi.id, 776 - hw->cap_act_pri_cfi.variant, hw->cap_act_pri_cfi.bottom, 777 - hw->cap_act_pri_cfi.top); 778 - 779 - /* Compatibility range, sta f/w actor, CFI supplier */ 780 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_CFIACTRANGES, 781 - &hw->cap_act_sta_cfi, 782 - sizeof(struct hfa384x_caplevel)); 783 - if (result) { 784 - netdev_err(wlandev->netdev, "Failed to retrieve STA_CFIACTRANGES\n"); 785 - goto failed; 786 - } 787 - 788 - /* get all the Compatibility range, station f/w actor, CFI supplier 789 - * fields in byte order 790 - */ 791 - le16_to_cpus(&hw->cap_act_sta_cfi.role); 792 - le16_to_cpus(&hw->cap_act_sta_cfi.id); 793 - le16_to_cpus(&hw->cap_act_sta_cfi.variant); 794 - le16_to_cpus(&hw->cap_act_sta_cfi.bottom); 795 - le16_to_cpus(&hw->cap_act_sta_cfi.top); 796 - 797 - netdev_info(wlandev->netdev, 798 - "STA-CFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 799 - hw->cap_act_sta_cfi.role, hw->cap_act_sta_cfi.id, 800 - hw->cap_act_sta_cfi.variant, hw->cap_act_sta_cfi.bottom, 801 - hw->cap_act_sta_cfi.top); 802 - 803 - /* Compatibility range, sta f/w actor, MFI supplier */ 804 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_STA_MFIACTRANGES, 805 - &hw->cap_act_sta_mfi, 806 - sizeof(struct hfa384x_caplevel)); 807 - if (result) { 808 - netdev_err(wlandev->netdev, "Failed to retrieve STA_MFIACTRANGES\n"); 809 - goto failed; 810 - } 811 - 812 - /* get all the Compatibility range, station f/w actor, MFI supplier 813 - * fields in byte order 814 - */ 815 - le16_to_cpus(&hw->cap_act_sta_mfi.role); 816 - le16_to_cpus(&hw->cap_act_sta_mfi.id); 817 - le16_to_cpus(&hw->cap_act_sta_mfi.variant); 818 - le16_to_cpus(&hw->cap_act_sta_mfi.bottom); 819 - le16_to_cpus(&hw->cap_act_sta_mfi.top); 820 - 821 - netdev_info(wlandev->netdev, 822 - "STA-MFI:ACT:role=0x%02x:id=0x%02x:var=0x%02x:b/t=%d/%d\n", 823 - hw->cap_act_sta_mfi.role, hw->cap_act_sta_mfi.id, 824 - hw->cap_act_sta_mfi.variant, hw->cap_act_sta_mfi.bottom, 825 - hw->cap_act_sta_mfi.top); 826 - 827 - /* Serial Number */ 828 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_NICSERIALNUMBER, 829 - snum, HFA384x_RID_NICSERIALNUMBER_LEN); 830 - if (!result) { 831 - netdev_info(wlandev->netdev, "Prism2 card SN: %*pE\n", 832 - HFA384x_RID_NICSERIALNUMBER_LEN, snum); 833 - } else { 834 - netdev_err(wlandev->netdev, "Failed to retrieve Prism2 Card SN\n"); 835 - goto failed; 836 - } 837 - 838 - /* Collect the MAC address */ 839 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR, 840 - addr, ETH_ALEN); 841 - if (result != 0) { 842 - netdev_err(wlandev->netdev, "Failed to retrieve mac address\n"); 843 - goto failed; 844 - } 845 - eth_hw_addr_set(wlandev->netdev, addr); 846 - 847 - /* short preamble is always implemented */ 848 - wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE; 849 - 850 - /* find out if hardware wep is implemented */ 851 - hfa384x_drvr_getconfig16(hw, HFA384x_RID_PRIVACYOPTIMP, &temp); 852 - if (temp) 853 - wlandev->nsdcaps |= P80211_NSDCAP_HARDWAREWEP; 854 - 855 - /* get the dBm Scaling constant */ 856 - hfa384x_drvr_getconfig16(hw, HFA384x_RID_CNFDBMADJUST, &temp); 857 - hw->dbmadjust = temp; 858 - 859 - /* Only enable scan by default on newer firmware */ 860 - if (HFA384x_FIRMWARE_VERSION(hw->ident_sta_fw.major, 861 - hw->ident_sta_fw.minor, 862 - hw->ident_sta_fw.variant) < 863 - HFA384x_FIRMWARE_VERSION(1, 5, 5)) { 864 - wlandev->nsdcaps |= P80211_NSDCAP_NOSCAN; 865 - } 866 - 867 - /* TODO: Set any internally managed config items */ 868 - 869 - goto done; 870 - failed: 871 - netdev_err(wlandev->netdev, "Failed, result=%d\n", result); 872 - done: 873 - return result; 874 - } 875 - 876 - /* 877 - * prism2sta_globalsetup 878 - * 879 - * Set any global RIDs that we want to set at device activation. 880 - * 881 - * Arguments: 882 - * wlandev wlan device structure 883 - * 884 - * Returns: 885 - * 0 success 886 - * >0 f/w reported error 887 - * <0 driver reported error 888 - * 889 - * Side effects: 890 - * 891 - * Call context: 892 - * process thread 893 - */ 894 - static int prism2sta_globalsetup(struct wlandevice *wlandev) 895 - { 896 - struct hfa384x *hw = wlandev->priv; 897 - 898 - /* Set the maximum frame size */ 899 - return hfa384x_drvr_setconfig16(hw, HFA384x_RID_CNFMAXDATALEN, 900 - WLAN_DATA_MAXLEN); 901 - } 902 - 903 - static int prism2sta_setmulticast(struct wlandevice *wlandev, 904 - struct net_device *dev) 905 - { 906 - int result = 0; 907 - struct hfa384x *hw = wlandev->priv; 908 - 909 - u16 promisc; 910 - 911 - /* If we're not ready, what's the point? */ 912 - if (hw->state != HFA384x_STATE_RUNNING) 913 - goto exit; 914 - 915 - if ((dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) != 0) 916 - promisc = P80211ENUM_truth_true; 917 - else 918 - promisc = P80211ENUM_truth_false; 919 - 920 - result = 921 - hfa384x_drvr_setconfig16_async(hw, HFA384x_RID_PROMISCMODE, 922 - promisc); 923 - exit: 924 - return result; 925 - } 926 - 927 - /* 928 - * prism2sta_inf_tallies 929 - * 930 - * Handles the receipt of a CommTallies info frame. 931 - * 932 - * Arguments: 933 - * wlandev wlan device structure 934 - * inf ptr to info frame (contents in hfa384x order) 935 - * 936 - * Returns: 937 - * nothing 938 - * 939 - * Side effects: 940 - * 941 - * Call context: 942 - * interrupt 943 - */ 944 - static void prism2sta_inf_tallies(struct wlandevice *wlandev, 945 - struct hfa384x_inf_frame *inf) 946 - { 947 - struct hfa384x *hw = wlandev->priv; 948 - __le16 *src16; 949 - u32 *dst; 950 - __le32 *src32; 951 - int i; 952 - int cnt; 953 - 954 - /* 955 - * Determine if these are 16-bit or 32-bit tallies, based on the 956 - * record length of the info record. 957 - */ 958 - 959 - cnt = sizeof(struct hfa384x_comm_tallies_32) / sizeof(u32); 960 - if (inf->framelen > 22) { 961 - dst = (u32 *)&hw->tallies; 962 - src32 = (__le32 *)&inf->info.commtallies32; 963 - for (i = 0; i < cnt; i++, dst++, src32++) 964 - *dst += le32_to_cpu(*src32); 965 - } else { 966 - dst = (u32 *)&hw->tallies; 967 - src16 = (__le16 *)&inf->info.commtallies16; 968 - for (i = 0; i < cnt; i++, dst++, src16++) 969 - *dst += le16_to_cpu(*src16); 970 - } 971 - } 972 - 973 - /* 974 - * prism2sta_inf_scanresults 975 - * 976 - * Handles the receipt of a Scan Results info frame. 977 - * 978 - * Arguments: 979 - * wlandev wlan device structure 980 - * inf ptr to info frame (contents in hfa384x order) 981 - * 982 - * Returns: 983 - * nothing 984 - * 985 - * Side effects: 986 - * 987 - * Call context: 988 - * interrupt 989 - */ 990 - static void prism2sta_inf_scanresults(struct wlandevice *wlandev, 991 - struct hfa384x_inf_frame *inf) 992 - { 993 - struct hfa384x *hw = wlandev->priv; 994 - int nbss; 995 - struct hfa384x_scan_result *sr = &inf->info.scanresult; 996 - int i; 997 - struct hfa384x_join_request_data joinreq; 998 - int result; 999 - 1000 - /* Get the number of results, first in bytes, then in results */ 1001 - nbss = (inf->framelen * sizeof(u16)) - 1002 - sizeof(inf->infotype) - sizeof(inf->info.scanresult.scanreason); 1003 - nbss /= sizeof(struct hfa384x_scan_result_sub); 1004 - 1005 - /* Print em */ 1006 - netdev_dbg(wlandev->netdev, "rx scanresults, reason=%d, nbss=%d:\n", 1007 - inf->info.scanresult.scanreason, nbss); 1008 - for (i = 0; i < nbss; i++) { 1009 - netdev_dbg(wlandev->netdev, "chid=%d anl=%d sl=%d bcnint=%d\n", 1010 - sr->result[i].chid, sr->result[i].anl, 1011 - sr->result[i].sl, sr->result[i].bcnint); 1012 - netdev_dbg(wlandev->netdev, 1013 - " capinfo=0x%04x proberesp_rate=%d\n", 1014 - sr->result[i].capinfo, sr->result[i].proberesp_rate); 1015 - } 1016 - /* issue a join request */ 1017 - joinreq.channel = sr->result[0].chid; 1018 - memcpy(joinreq.bssid, sr->result[0].bssid, WLAN_BSSID_LEN); 1019 - result = hfa384x_drvr_setconfig(hw, 1020 - HFA384x_RID_JOINREQUEST, 1021 - &joinreq, HFA384x_RID_JOINREQUEST_LEN); 1022 - if (result) { 1023 - netdev_err(wlandev->netdev, "setconfig(joinreq) failed, result=%d\n", 1024 - result); 1025 - } 1026 - } 1027 - 1028 - /* 1029 - * prism2sta_inf_hostscanresults 1030 - * 1031 - * Handles the receipt of a Scan Results info frame. 1032 - * 1033 - * Arguments: 1034 - * wlandev wlan device structure 1035 - * inf ptr to info frame (contents in hfa384x order) 1036 - * 1037 - * Returns: 1038 - * nothing 1039 - * 1040 - * Side effects: 1041 - * 1042 - * Call context: 1043 - * interrupt 1044 - */ 1045 - static void prism2sta_inf_hostscanresults(struct wlandevice *wlandev, 1046 - struct hfa384x_inf_frame *inf) 1047 - { 1048 - struct hfa384x *hw = wlandev->priv; 1049 - int nbss; 1050 - 1051 - nbss = (inf->framelen - 3) / 32; 1052 - netdev_dbg(wlandev->netdev, "Received %d hostscan results\n", nbss); 1053 - 1054 - if (nbss > 32) 1055 - nbss = 32; 1056 - 1057 - kfree(hw->scanresults); 1058 - 1059 - hw->scanresults = kmemdup(inf, sizeof(*inf), GFP_ATOMIC); 1060 - 1061 - if (nbss == 0) 1062 - nbss = -1; 1063 - 1064 - /* Notify/wake the sleeping caller. */ 1065 - hw->scanflag = nbss; 1066 - wake_up_interruptible(&hw->cmdq); 1067 - }; 1068 - 1069 - /* 1070 - * prism2sta_inf_chinforesults 1071 - * 1072 - * Handles the receipt of a Channel Info Results info frame. 1073 - * 1074 - * Arguments: 1075 - * wlandev wlan device structure 1076 - * inf ptr to info frame (contents in hfa384x order) 1077 - * 1078 - * Returns: 1079 - * nothing 1080 - * 1081 - * Side effects: 1082 - * 1083 - * Call context: 1084 - * interrupt 1085 - */ 1086 - static void prism2sta_inf_chinforesults(struct wlandevice *wlandev, 1087 - struct hfa384x_inf_frame *inf) 1088 - { 1089 - struct hfa384x *hw = wlandev->priv; 1090 - unsigned int i, n; 1091 - 1092 - hw->channel_info.results.scanchannels = 1093 - inf->info.chinforesult.scanchannels; 1094 - 1095 - for (i = 0, n = 0; i < HFA384x_CHINFORESULT_MAX; i++) { 1096 - struct hfa384x_ch_info_result_sub *result; 1097 - struct hfa384x_ch_info_result_sub *chinforesult; 1098 - int chan; 1099 - 1100 - if (!(hw->channel_info.results.scanchannels & (1 << i))) 1101 - continue; 1102 - 1103 - result = &inf->info.chinforesult.result[n]; 1104 - chan = result->chid - 1; 1105 - 1106 - if (chan < 0 || chan >= HFA384x_CHINFORESULT_MAX) 1107 - continue; 1108 - 1109 - chinforesult = &hw->channel_info.results.result[chan]; 1110 - chinforesult->chid = chan; 1111 - chinforesult->anl = result->anl; 1112 - chinforesult->pnl = result->pnl; 1113 - chinforesult->active = result->active; 1114 - 1115 - netdev_dbg(wlandev->netdev, 1116 - "chinfo: channel %d, %s level (avg/peak)=%d/%d dB, pcf %d\n", 1117 - chan + 1, 1118 - (chinforesult->active & HFA384x_CHINFORESULT_BSSACTIVE) ? 1119 - "signal" : "noise", 1120 - chinforesult->anl, 1121 - chinforesult->pnl, 1122 - (chinforesult->active & HFA384x_CHINFORESULT_PCFACTIVE) ? 1 : 0); 1123 - n++; 1124 - } 1125 - atomic_set(&hw->channel_info.done, 2); 1126 - 1127 - hw->channel_info.count = n; 1128 - } 1129 - 1130 - void prism2sta_processing_defer(struct work_struct *data) 1131 - { 1132 - struct hfa384x *hw = container_of(data, struct hfa384x, link_bh); 1133 - struct wlandevice *wlandev = hw->wlandev; 1134 - struct hfa384x_bytestr32 ssid; 1135 - int result; 1136 - 1137 - /* First let's process the auth frames */ 1138 - { 1139 - struct sk_buff *skb; 1140 - struct hfa384x_inf_frame *inf; 1141 - 1142 - while ((skb = skb_dequeue(&hw->authq))) { 1143 - inf = (struct hfa384x_inf_frame *)skb->data; 1144 - prism2sta_inf_authreq_defer(wlandev, inf); 1145 - } 1146 - } 1147 - 1148 - /* Now let's handle the linkstatus stuff */ 1149 - if (hw->link_status == hw->link_status_new) 1150 - return; 1151 - 1152 - hw->link_status = hw->link_status_new; 1153 - 1154 - switch (hw->link_status) { 1155 - case HFA384x_LINK_NOTCONNECTED: 1156 - /* I'm currently assuming that this is the initial link 1157 - * state. It should only be possible immediately 1158 - * following an Enable command. 1159 - * Response: 1160 - * Block Transmits, Ignore receives of data frames 1161 - */ 1162 - netif_carrier_off(wlandev->netdev); 1163 - 1164 - netdev_info(wlandev->netdev, "linkstatus=NOTCONNECTED (unhandled)\n"); 1165 - break; 1166 - 1167 - case HFA384x_LINK_CONNECTED: 1168 - /* This one indicates a successful scan/join/auth/assoc. 1169 - * When we have the full MLME complement, this event will 1170 - * signify successful completion of both mlme_authenticate 1171 - * and mlme_associate. State management will get a little 1172 - * ugly here. 1173 - * Response: 1174 - * Indicate authentication and/or association 1175 - * Enable Transmits, Receives and pass up data frames 1176 - */ 1177 - 1178 - netif_carrier_on(wlandev->netdev); 1179 - 1180 - /* If we are joining a specific AP, set our 1181 - * state and reset retries 1182 - */ 1183 - if (hw->join_ap == 1) 1184 - hw->join_ap = 2; 1185 - hw->join_retries = 60; 1186 - 1187 - /* Don't call this in monitor mode */ 1188 - if (wlandev->netdev->type == ARPHRD_ETHER) { 1189 - u16 portstatus; 1190 - 1191 - netdev_info(wlandev->netdev, "linkstatus=CONNECTED\n"); 1192 - 1193 - /* For non-usb devices, we can use the sync versions */ 1194 - /* Collect the BSSID, and set state to allow tx */ 1195 - 1196 - result = hfa384x_drvr_getconfig(hw, 1197 - HFA384x_RID_CURRENTBSSID, 1198 - wlandev->bssid, 1199 - WLAN_BSSID_LEN); 1200 - if (result) { 1201 - netdev_dbg(wlandev->netdev, 1202 - "getconfig(0x%02x) failed, result = %d\n", 1203 - HFA384x_RID_CURRENTBSSID, result); 1204 - return; 1205 - } 1206 - 1207 - result = hfa384x_drvr_getconfig(hw, 1208 - HFA384x_RID_CURRENTSSID, 1209 - &ssid, sizeof(ssid)); 1210 - if (result) { 1211 - netdev_dbg(wlandev->netdev, 1212 - "getconfig(0x%02x) failed, result = %d\n", 1213 - HFA384x_RID_CURRENTSSID, result); 1214 - return; 1215 - } 1216 - prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid, 1217 - (struct p80211pstrd *)&wlandev->ssid); 1218 - 1219 - /* Collect the port status */ 1220 - result = hfa384x_drvr_getconfig16(hw, 1221 - HFA384x_RID_PORTSTATUS, 1222 - &portstatus); 1223 - if (result) { 1224 - netdev_dbg(wlandev->netdev, 1225 - "getconfig(0x%02x) failed, result = %d\n", 1226 - HFA384x_RID_PORTSTATUS, result); 1227 - return; 1228 - } 1229 - wlandev->macmode = 1230 - (portstatus == HFA384x_PSTATUS_CONN_IBSS) ? 1231 - WLAN_MACMODE_IBSS_STA : WLAN_MACMODE_ESS_STA; 1232 - 1233 - /* signal back up to cfg80211 layer */ 1234 - prism2_connect_result(wlandev, P80211ENUM_truth_false); 1235 - 1236 - /* Get the ball rolling on the comms quality stuff */ 1237 - prism2sta_commsqual_defer(&hw->commsqual_bh); 1238 - } 1239 - break; 1240 - 1241 - case HFA384x_LINK_DISCONNECTED: 1242 - /* This one indicates that our association is gone. We've 1243 - * lost connection with the AP and/or been disassociated. 1244 - * This indicates that the MAC has completely cleared it's 1245 - * associated state. We * should send a deauth indication 1246 - * (implying disassoc) up * to the MLME. 1247 - * Response: 1248 - * Indicate Deauthentication 1249 - * Block Transmits, Ignore receives of data frames 1250 - */ 1251 - if (wlandev->netdev->type == ARPHRD_ETHER) 1252 - netdev_info(wlandev->netdev, 1253 - "linkstatus=DISCONNECTED (unhandled)\n"); 1254 - wlandev->macmode = WLAN_MACMODE_NONE; 1255 - 1256 - netif_carrier_off(wlandev->netdev); 1257 - 1258 - /* signal back up to cfg80211 layer */ 1259 - prism2_disconnected(wlandev); 1260 - 1261 - break; 1262 - 1263 - case HFA384x_LINK_AP_CHANGE: 1264 - /* This one indicates that the MAC has decided to and 1265 - * successfully completed a change to another AP. We 1266 - * should probably implement a reassociation indication 1267 - * in response to this one. I'm thinking that the 1268 - * p80211 layer needs to be notified in case of 1269 - * buffering/queueing issues. User mode also needs to be 1270 - * notified so that any BSS dependent elements can be 1271 - * updated. 1272 - * associated state. We * should send a deauth indication 1273 - * (implying disassoc) up * to the MLME. 1274 - * Response: 1275 - * Indicate Reassociation 1276 - * Enable Transmits, Receives and pass up data frames 1277 - */ 1278 - netdev_info(wlandev->netdev, "linkstatus=AP_CHANGE\n"); 1279 - 1280 - result = hfa384x_drvr_getconfig(hw, 1281 - HFA384x_RID_CURRENTBSSID, 1282 - wlandev->bssid, WLAN_BSSID_LEN); 1283 - if (result) { 1284 - netdev_dbg(wlandev->netdev, 1285 - "getconfig(0x%02x) failed, result = %d\n", 1286 - HFA384x_RID_CURRENTBSSID, result); 1287 - return; 1288 - } 1289 - 1290 - result = hfa384x_drvr_getconfig(hw, 1291 - HFA384x_RID_CURRENTSSID, 1292 - &ssid, sizeof(ssid)); 1293 - if (result) { 1294 - netdev_dbg(wlandev->netdev, 1295 - "getconfig(0x%02x) failed, result = %d\n", 1296 - HFA384x_RID_CURRENTSSID, result); 1297 - return; 1298 - } 1299 - prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid, 1300 - (struct p80211pstrd *)&wlandev->ssid); 1301 - 1302 - hw->link_status = HFA384x_LINK_CONNECTED; 1303 - netif_carrier_on(wlandev->netdev); 1304 - 1305 - /* signal back up to cfg80211 layer */ 1306 - prism2_roamed(wlandev); 1307 - 1308 - break; 1309 - 1310 - case HFA384x_LINK_AP_OUTOFRANGE: 1311 - /* This one indicates that the MAC has decided that the 1312 - * AP is out of range, but hasn't found a better candidate 1313 - * so the MAC maintains its "associated" state in case 1314 - * we get back in range. We should block transmits and 1315 - * receives in this state. Do we need an indication here? 1316 - * Probably not since a polling user-mode element would 1317 - * get this status from p2PortStatus(FD40). What about 1318 - * p80211? 1319 - * Response: 1320 - * Block Transmits, Ignore receives of data frames 1321 - */ 1322 - netdev_info(wlandev->netdev, "linkstatus=AP_OUTOFRANGE (unhandled)\n"); 1323 - 1324 - netif_carrier_off(wlandev->netdev); 1325 - 1326 - break; 1327 - 1328 - case HFA384x_LINK_AP_INRANGE: 1329 - /* This one indicates that the MAC has decided that the 1330 - * AP is back in range. We continue working with our 1331 - * existing association. 1332 - * Response: 1333 - * Enable Transmits, Receives and pass up data frames 1334 - */ 1335 - netdev_info(wlandev->netdev, "linkstatus=AP_INRANGE\n"); 1336 - 1337 - hw->link_status = HFA384x_LINK_CONNECTED; 1338 - netif_carrier_on(wlandev->netdev); 1339 - 1340 - break; 1341 - 1342 - case HFA384x_LINK_ASSOCFAIL: 1343 - /* This one is actually a peer to CONNECTED. We've 1344 - * requested a join for a given SSID and optionally BSSID. 1345 - * We can use this one to indicate authentication and 1346 - * association failures. The trick is going to be 1347 - * 1) identifying the failure, and 2) state management. 1348 - * Response: 1349 - * Disable Transmits, Ignore receives of data frames 1350 - */ 1351 - if (hw->join_ap && --hw->join_retries > 0) { 1352 - struct hfa384x_join_request_data joinreq; 1353 - 1354 - joinreq = hw->joinreq; 1355 - /* Send the join request */ 1356 - hfa384x_drvr_setconfig(hw, 1357 - HFA384x_RID_JOINREQUEST, 1358 - &joinreq, 1359 - HFA384x_RID_JOINREQUEST_LEN); 1360 - netdev_info(wlandev->netdev, 1361 - "linkstatus=ASSOCFAIL (re-submitting join)\n"); 1362 - } else { 1363 - netdev_info(wlandev->netdev, "linkstatus=ASSOCFAIL (unhandled)\n"); 1364 - } 1365 - 1366 - netif_carrier_off(wlandev->netdev); 1367 - 1368 - /* signal back up to cfg80211 layer */ 1369 - prism2_connect_result(wlandev, P80211ENUM_truth_true); 1370 - 1371 - break; 1372 - 1373 - default: 1374 - /* This is bad, IO port problems? */ 1375 - netdev_warn(wlandev->netdev, 1376 - "unknown linkstatus=0x%02x\n", hw->link_status); 1377 - return; 1378 - } 1379 - 1380 - wlandev->linkstatus = (hw->link_status == HFA384x_LINK_CONNECTED); 1381 - } 1382 - 1383 - /* 1384 - * prism2sta_inf_linkstatus 1385 - * 1386 - * Handles the receipt of a Link Status info frame. 1387 - * 1388 - * Arguments: 1389 - * wlandev wlan device structure 1390 - * inf ptr to info frame (contents in hfa384x order) 1391 - * 1392 - * Returns: 1393 - * nothing 1394 - * 1395 - * Side effects: 1396 - * 1397 - * Call context: 1398 - * interrupt 1399 - */ 1400 - static void prism2sta_inf_linkstatus(struct wlandevice *wlandev, 1401 - struct hfa384x_inf_frame *inf) 1402 - { 1403 - struct hfa384x *hw = wlandev->priv; 1404 - 1405 - hw->link_status_new = le16_to_cpu(inf->info.linkstatus.linkstatus); 1406 - 1407 - schedule_work(&hw->link_bh); 1408 - } 1409 - 1410 - /* 1411 - * prism2sta_inf_assocstatus 1412 - * 1413 - * Handles the receipt of an Association Status info frame. Should 1414 - * be present in APs only. 1415 - * 1416 - * Arguments: 1417 - * wlandev wlan device structure 1418 - * inf ptr to info frame (contents in hfa384x order) 1419 - * 1420 - * Returns: 1421 - * nothing 1422 - * 1423 - * Side effects: 1424 - * 1425 - * Call context: 1426 - * interrupt 1427 - */ 1428 - static void prism2sta_inf_assocstatus(struct wlandevice *wlandev, 1429 - struct hfa384x_inf_frame *inf) 1430 - { 1431 - struct hfa384x *hw = wlandev->priv; 1432 - struct hfa384x_assoc_status rec; 1433 - int i; 1434 - 1435 - memcpy(&rec, &inf->info.assocstatus, sizeof(rec)); 1436 - le16_to_cpus(&rec.assocstatus); 1437 - le16_to_cpus(&rec.reason); 1438 - 1439 - /* 1440 - * Find the address in the list of authenticated stations. 1441 - * If it wasn't found, then this address has not been previously 1442 - * authenticated and something weird has happened if this is 1443 - * anything other than an "authentication failed" message. 1444 - * If the address was found, then set the "associated" flag for 1445 - * that station, based on whether the station is associating or 1446 - * losing its association. Something weird has also happened 1447 - * if we find the address in the list of authenticated stations 1448 - * but we are getting an "authentication failed" message. 1449 - */ 1450 - 1451 - for (i = 0; i < hw->authlist.cnt; i++) 1452 - if (ether_addr_equal(rec.sta_addr, hw->authlist.addr[i])) 1453 - break; 1454 - 1455 - if (i >= hw->authlist.cnt) { 1456 - if (rec.assocstatus != HFA384x_ASSOCSTATUS_AUTHFAIL) 1457 - netdev_warn(wlandev->netdev, 1458 - "assocstatus info frame received for non-authenticated station.\n"); 1459 - } else { 1460 - hw->authlist.assoc[i] = 1461 - (rec.assocstatus == HFA384x_ASSOCSTATUS_STAASSOC || 1462 - rec.assocstatus == HFA384x_ASSOCSTATUS_REASSOC); 1463 - 1464 - if (rec.assocstatus == HFA384x_ASSOCSTATUS_AUTHFAIL) 1465 - netdev_warn(wlandev->netdev, 1466 - "authfail assocstatus info frame received for authenticated station.\n"); 1467 - } 1468 - } 1469 - 1470 - /* 1471 - * prism2sta_inf_authreq 1472 - * 1473 - * Handles the receipt of an Authentication Request info frame. Should 1474 - * be present in APs only. 1475 - * 1476 - * Arguments: 1477 - * wlandev wlan device structure 1478 - * inf ptr to info frame (contents in hfa384x order) 1479 - * 1480 - * Returns: 1481 - * nothing 1482 - * 1483 - * Side effects: 1484 - * 1485 - * Call context: 1486 - * interrupt 1487 - * 1488 - */ 1489 - static void prism2sta_inf_authreq(struct wlandevice *wlandev, 1490 - struct hfa384x_inf_frame *inf) 1491 - { 1492 - struct hfa384x *hw = wlandev->priv; 1493 - struct sk_buff *skb; 1494 - 1495 - skb = dev_alloc_skb(sizeof(*inf)); 1496 - if (skb) { 1497 - skb_put(skb, sizeof(*inf)); 1498 - memcpy(skb->data, inf, sizeof(*inf)); 1499 - skb_queue_tail(&hw->authq, skb); 1500 - schedule_work(&hw->link_bh); 1501 - } 1502 - } 1503 - 1504 - static void prism2sta_inf_authreq_defer(struct wlandevice *wlandev, 1505 - struct hfa384x_inf_frame *inf) 1506 - { 1507 - struct hfa384x *hw = wlandev->priv; 1508 - struct hfa384x_authenticate_station_data rec; 1509 - 1510 - int i, added, result, cnt; 1511 - u8 *addr; 1512 - 1513 - /* 1514 - * Build the AuthenticateStation record. Initialize it for denying 1515 - * authentication. 1516 - */ 1517 - 1518 - ether_addr_copy(rec.address, inf->info.authreq.sta_addr); 1519 - rec.status = cpu_to_le16(P80211ENUM_status_unspec_failure); 1520 - 1521 - /* 1522 - * Authenticate based on the access mode. 1523 - */ 1524 - 1525 - switch (hw->accessmode) { 1526 - case WLAN_ACCESS_NONE: 1527 - 1528 - /* 1529 - * Deny all new authentications. However, if a station 1530 - * is ALREADY authenticated, then accept it. 1531 - */ 1532 - 1533 - for (i = 0; i < hw->authlist.cnt; i++) 1534 - if (ether_addr_equal(rec.address, 1535 - hw->authlist.addr[i])) { 1536 - rec.status = cpu_to_le16(P80211ENUM_status_successful); 1537 - break; 1538 - } 1539 - 1540 - break; 1541 - 1542 - case WLAN_ACCESS_ALL: 1543 - 1544 - /* 1545 - * Allow all authentications. 1546 - */ 1547 - 1548 - rec.status = cpu_to_le16(P80211ENUM_status_successful); 1549 - break; 1550 - 1551 - case WLAN_ACCESS_ALLOW: 1552 - 1553 - /* 1554 - * Only allow the authentication if the MAC address 1555 - * is in the list of allowed addresses. 1556 - * 1557 - * Since this is the interrupt handler, we may be here 1558 - * while the access list is in the middle of being 1559 - * updated. Choose the list which is currently okay. 1560 - * See "prism2mib_priv_accessallow()" for details. 1561 - */ 1562 - 1563 - if (hw->allow.modify == 0) { 1564 - cnt = hw->allow.cnt; 1565 - addr = hw->allow.addr[0]; 1566 - } else { 1567 - cnt = hw->allow.cnt1; 1568 - addr = hw->allow.addr1[0]; 1569 - } 1570 - 1571 - for (i = 0; i < cnt; i++, addr += ETH_ALEN) 1572 - if (ether_addr_equal(rec.address, addr)) { 1573 - rec.status = cpu_to_le16(P80211ENUM_status_successful); 1574 - break; 1575 - } 1576 - 1577 - break; 1578 - 1579 - case WLAN_ACCESS_DENY: 1580 - 1581 - /* 1582 - * Allow the authentication UNLESS the MAC address is 1583 - * in the list of denied addresses. 1584 - * 1585 - * Since this is the interrupt handler, we may be here 1586 - * while the access list is in the middle of being 1587 - * updated. Choose the list which is currently okay. 1588 - * See "prism2mib_priv_accessdeny()" for details. 1589 - */ 1590 - 1591 - if (hw->deny.modify == 0) { 1592 - cnt = hw->deny.cnt; 1593 - addr = hw->deny.addr[0]; 1594 - } else { 1595 - cnt = hw->deny.cnt1; 1596 - addr = hw->deny.addr1[0]; 1597 - } 1598 - 1599 - rec.status = cpu_to_le16(P80211ENUM_status_successful); 1600 - 1601 - for (i = 0; i < cnt; i++, addr += ETH_ALEN) 1602 - if (ether_addr_equal(rec.address, addr)) { 1603 - rec.status = cpu_to_le16(P80211ENUM_status_unspec_failure); 1604 - break; 1605 - } 1606 - 1607 - break; 1608 - } 1609 - 1610 - /* 1611 - * If the authentication is okay, then add the MAC address to the 1612 - * list of authenticated stations. Don't add the address if it 1613 - * is already in the list. (802.11b does not seem to disallow 1614 - * a station from issuing an authentication request when the 1615 - * station is already authenticated. Does this sort of thing 1616 - * ever happen? We might as well do the check just in case.) 1617 - */ 1618 - 1619 - added = 0; 1620 - 1621 - if (rec.status == cpu_to_le16(P80211ENUM_status_successful)) { 1622 - for (i = 0; i < hw->authlist.cnt; i++) 1623 - if (ether_addr_equal(rec.address, 1624 - hw->authlist.addr[i])) 1625 - break; 1626 - 1627 - if (i >= hw->authlist.cnt) { 1628 - if (hw->authlist.cnt >= WLAN_AUTH_MAX) { 1629 - rec.status = cpu_to_le16(P80211ENUM_status_ap_full); 1630 - } else { 1631 - ether_addr_copy(hw->authlist.addr[hw->authlist.cnt], 1632 - rec.address); 1633 - hw->authlist.cnt++; 1634 - added = 1; 1635 - } 1636 - } 1637 - } 1638 - 1639 - /* 1640 - * Send back the results of the authentication. If this doesn't work, 1641 - * then make sure to remove the address from the authenticated list if 1642 - * it was added. 1643 - */ 1644 - 1645 - rec.algorithm = inf->info.authreq.algorithm; 1646 - 1647 - result = hfa384x_drvr_setconfig(hw, HFA384x_RID_AUTHENTICATESTA, 1648 - &rec, sizeof(rec)); 1649 - if (result) { 1650 - if (added) 1651 - hw->authlist.cnt--; 1652 - netdev_err(wlandev->netdev, 1653 - "setconfig(authenticatestation) failed, result=%d\n", 1654 - result); 1655 - } 1656 - } 1657 - 1658 - /* 1659 - * prism2sta_inf_psusercnt 1660 - * 1661 - * Handles the receipt of a PowerSaveUserCount info frame. Should 1662 - * be present in APs only. 1663 - * 1664 - * Arguments: 1665 - * wlandev wlan device structure 1666 - * inf ptr to info frame (contents in hfa384x order) 1667 - * 1668 - * Returns: 1669 - * nothing 1670 - * 1671 - * Side effects: 1672 - * 1673 - * Call context: 1674 - * interrupt 1675 - */ 1676 - static void prism2sta_inf_psusercnt(struct wlandevice *wlandev, 1677 - struct hfa384x_inf_frame *inf) 1678 - { 1679 - struct hfa384x *hw = wlandev->priv; 1680 - 1681 - hw->psusercount = le16_to_cpu(inf->info.psusercnt.usercnt); 1682 - } 1683 - 1684 - /* 1685 - * prism2sta_ev_info 1686 - * 1687 - * Handles the Info event. 1688 - * 1689 - * Arguments: 1690 - * wlandev wlan device structure 1691 - * inf ptr to a generic info frame 1692 - * 1693 - * Returns: 1694 - * nothing 1695 - * 1696 - * Side effects: 1697 - * 1698 - * Call context: 1699 - * interrupt 1700 - */ 1701 - void prism2sta_ev_info(struct wlandevice *wlandev, 1702 - struct hfa384x_inf_frame *inf) 1703 - { 1704 - le16_to_cpus(&inf->infotype); 1705 - /* Dispatch */ 1706 - switch (inf->infotype) { 1707 - case HFA384x_IT_HANDOVERADDR: 1708 - netdev_dbg(wlandev->netdev, 1709 - "received infoframe:HANDOVER (unhandled)\n"); 1710 - break; 1711 - case HFA384x_IT_COMMTALLIES: 1712 - prism2sta_inf_tallies(wlandev, inf); 1713 - break; 1714 - case HFA384x_IT_HOSTSCANRESULTS: 1715 - prism2sta_inf_hostscanresults(wlandev, inf); 1716 - break; 1717 - case HFA384x_IT_SCANRESULTS: 1718 - prism2sta_inf_scanresults(wlandev, inf); 1719 - break; 1720 - case HFA384x_IT_CHINFORESULTS: 1721 - prism2sta_inf_chinforesults(wlandev, inf); 1722 - break; 1723 - case HFA384x_IT_LINKSTATUS: 1724 - prism2sta_inf_linkstatus(wlandev, inf); 1725 - break; 1726 - case HFA384x_IT_ASSOCSTATUS: 1727 - prism2sta_inf_assocstatus(wlandev, inf); 1728 - break; 1729 - case HFA384x_IT_AUTHREQ: 1730 - prism2sta_inf_authreq(wlandev, inf); 1731 - break; 1732 - case HFA384x_IT_PSUSERCNT: 1733 - prism2sta_inf_psusercnt(wlandev, inf); 1734 - break; 1735 - case HFA384x_IT_KEYIDCHANGED: 1736 - netdev_warn(wlandev->netdev, "Unhandled IT_KEYIDCHANGED\n"); 1737 - break; 1738 - case HFA384x_IT_ASSOCREQ: 1739 - netdev_warn(wlandev->netdev, "Unhandled IT_ASSOCREQ\n"); 1740 - break; 1741 - case HFA384x_IT_MICFAILURE: 1742 - netdev_warn(wlandev->netdev, "Unhandled IT_MICFAILURE\n"); 1743 - break; 1744 - default: 1745 - netdev_warn(wlandev->netdev, 1746 - "Unknown info type=0x%02x\n", inf->infotype); 1747 - break; 1748 - } 1749 - } 1750 - 1751 - /* 1752 - * prism2sta_ev_tx 1753 - * 1754 - * Handles the Tx event. 1755 - * 1756 - * Arguments: 1757 - * wlandev wlan device structure 1758 - * status tx frame status word 1759 - * Returns: 1760 - * nothing 1761 - * 1762 - * Side effects: 1763 - * 1764 - * Call context: 1765 - * interrupt 1766 - */ 1767 - void prism2sta_ev_tx(struct wlandevice *wlandev, u16 status) 1768 - { 1769 - netdev_dbg(wlandev->netdev, "Tx Complete, status=0x%04x\n", status); 1770 - /* update linux network stats */ 1771 - wlandev->netdev->stats.tx_packets++; 1772 - } 1773 - 1774 - /* 1775 - * prism2sta_ev_alloc 1776 - * 1777 - * Handles the Alloc event. 1778 - * 1779 - * Arguments: 1780 - * wlandev wlan device structure 1781 - * 1782 - * Returns: 1783 - * nothing 1784 - * 1785 - * Side effects: 1786 - * 1787 - * Call context: 1788 - * interrupt 1789 - */ 1790 - void prism2sta_ev_alloc(struct wlandevice *wlandev) 1791 - { 1792 - netif_wake_queue(wlandev->netdev); 1793 - } 1794 - 1795 - /* 1796 - * create_wlan 1797 - * 1798 - * Called at module init time. This creates the struct wlandevice structure 1799 - * and initializes it with relevant bits. 1800 - * 1801 - * Arguments: 1802 - * none 1803 - * 1804 - * Returns: 1805 - * the created struct wlandevice structure. 1806 - * 1807 - * Side effects: 1808 - * also allocates the priv/hw structures. 1809 - * 1810 - * Call context: 1811 - * process thread 1812 - * 1813 - */ 1814 - static struct wlandevice *create_wlan(void) 1815 - { 1816 - struct wlandevice *wlandev = NULL; 1817 - struct hfa384x *hw = NULL; 1818 - 1819 - /* Alloc our structures */ 1820 - wlandev = kzalloc(sizeof(*wlandev), GFP_KERNEL); 1821 - hw = kzalloc(sizeof(*hw), GFP_KERNEL); 1822 - 1823 - if (!wlandev || !hw) { 1824 - kfree(wlandev); 1825 - kfree(hw); 1826 - return NULL; 1827 - } 1828 - 1829 - /* Initialize the network device object. */ 1830 - wlandev->nsdname = dev_info; 1831 - wlandev->msdstate = WLAN_MSD_HWPRESENT_PENDING; 1832 - wlandev->priv = hw; 1833 - wlandev->open = prism2sta_open; 1834 - wlandev->close = prism2sta_close; 1835 - wlandev->reset = prism2sta_reset; 1836 - wlandev->txframe = prism2sta_txframe; 1837 - wlandev->mlmerequest = prism2sta_mlmerequest; 1838 - wlandev->set_multicast_list = prism2sta_setmulticast; 1839 - wlandev->tx_timeout = hfa384x_tx_timeout; 1840 - 1841 - wlandev->nsdcaps = P80211_NSDCAP_HWFRAGMENT | P80211_NSDCAP_AUTOJOIN; 1842 - 1843 - /* Initialize the device private data structure. */ 1844 - hw->dot11_desired_bss_type = 1; 1845 - 1846 - return wlandev; 1847 - } 1848 - 1849 - void prism2sta_commsqual_defer(struct work_struct *data) 1850 - { 1851 - struct hfa384x *hw = container_of(data, struct hfa384x, commsqual_bh); 1852 - struct wlandevice *wlandev = hw->wlandev; 1853 - struct hfa384x_bytestr32 ssid; 1854 - struct p80211msg_dot11req_mibget msg; 1855 - struct p80211item_uint32 *mibitem = (struct p80211item_uint32 *) 1856 - &msg.mibattribute.data; 1857 - int result = 0; 1858 - 1859 - if (hw->wlandev->hwremoved) 1860 - return; 1861 - 1862 - /* we don't care if we're in AP mode */ 1863 - if ((wlandev->macmode == WLAN_MACMODE_NONE) || 1864 - (wlandev->macmode == WLAN_MACMODE_ESS_AP)) { 1865 - return; 1866 - } 1867 - 1868 - /* It only makes sense to poll these in non-IBSS */ 1869 - if (wlandev->macmode != WLAN_MACMODE_IBSS_STA) { 1870 - result = hfa384x_drvr_getconfig(hw, HFA384x_RID_DBMCOMMSQUALITY, 1871 - &hw->qual, HFA384x_RID_DBMCOMMSQUALITY_LEN); 1872 - 1873 - if (result) { 1874 - netdev_err(wlandev->netdev, "error fetching commsqual\n"); 1875 - return; 1876 - } 1877 - 1878 - netdev_dbg(wlandev->netdev, "commsqual %d %d %d\n", 1879 - le16_to_cpu(hw->qual.cq_curr_bss), 1880 - le16_to_cpu(hw->qual.asl_curr_bss), 1881 - le16_to_cpu(hw->qual.anl_curr_fc)); 1882 - } 1883 - 1884 - /* Get the signal rate */ 1885 - msg.msgcode = DIDMSG_DOT11REQ_MIBGET; 1886 - mibitem->did = DIDMIB_P2_MAC_CURRENTTXRATE; 1887 - result = p80211req_dorequest(wlandev, (u8 *)&msg); 1888 - 1889 - if (result) { 1890 - netdev_dbg(wlandev->netdev, 1891 - "get signal rate failed, result = %d\n", result); 1892 - return; 1893 - } 1894 - 1895 - switch (mibitem->data) { 1896 - case HFA384x_RATEBIT_1: 1897 - hw->txrate = 10; 1898 - break; 1899 - case HFA384x_RATEBIT_2: 1900 - hw->txrate = 20; 1901 - break; 1902 - case HFA384x_RATEBIT_5dot5: 1903 - hw->txrate = 55; 1904 - break; 1905 - case HFA384x_RATEBIT_11: 1906 - hw->txrate = 110; 1907 - break; 1908 - default: 1909 - netdev_dbg(wlandev->netdev, "Bad ratebit (%d)\n", 1910 - mibitem->data); 1911 - } 1912 - 1913 - /* Lastly, we need to make sure the BSSID didn't change on us */ 1914 - result = hfa384x_drvr_getconfig(hw, 1915 - HFA384x_RID_CURRENTBSSID, 1916 - wlandev->bssid, WLAN_BSSID_LEN); 1917 - if (result) { 1918 - netdev_dbg(wlandev->netdev, 1919 - "getconfig(0x%02x) failed, result = %d\n", 1920 - HFA384x_RID_CURRENTBSSID, result); 1921 - return; 1922 - } 1923 - 1924 - result = hfa384x_drvr_getconfig(hw, 1925 - HFA384x_RID_CURRENTSSID, 1926 - &ssid, sizeof(ssid)); 1927 - if (result) { 1928 - netdev_dbg(wlandev->netdev, 1929 - "getconfig(0x%02x) failed, result = %d\n", 1930 - HFA384x_RID_CURRENTSSID, result); 1931 - return; 1932 - } 1933 - prism2mgmt_bytestr2pstr((struct hfa384x_bytestr *)&ssid, 1934 - (struct p80211pstrd *)&wlandev->ssid); 1935 - 1936 - /* Reschedule timer */ 1937 - mod_timer(&hw->commsqual_timer, jiffies + HZ); 1938 - } 1939 - 1940 - void prism2sta_commsqual_timer(struct timer_list *t) 1941 - { 1942 - struct hfa384x *hw = from_timer(hw, t, commsqual_timer); 1943 - 1944 - schedule_work(&hw->commsqual_bh); 1945 - }
-299
drivers/staging/wlan-ng/prism2usb.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - #include "hfa384x_usb.c" 3 - #include "prism2mgmt.c" 4 - #include "prism2mib.c" 5 - #include "prism2sta.c" 6 - #include "prism2fw.c" 7 - 8 - #define PRISM_DEV(vid, pid, name) \ 9 - { USB_DEVICE(vid, pid), \ 10 - .driver_info = (unsigned long)name } 11 - 12 - static const struct usb_device_id usb_prism_tbl[] = { 13 - PRISM_DEV(0x04bb, 0x0922, "IOData AirPort WN-B11/USBS"), 14 - PRISM_DEV(0x07aa, 0x0012, "Corega USB Wireless LAN Stick-11"), 15 - PRISM_DEV(0x09aa, 0x3642, "Prism2.x 11Mbps USB WLAN Adapter"), 16 - PRISM_DEV(0x1668, 0x0408, "Actiontec Prism2.5 11Mbps USB WLAN Adapter"), 17 - PRISM_DEV(0x1668, 0x0421, "Actiontec Prism2.5 11Mbps USB WLAN Adapter"), 18 - PRISM_DEV(0x1915, 0x2236, "Linksys WUSB11v3.0 11Mbps USB WLAN Adapter"), 19 - PRISM_DEV(0x066b, 0x2212, "Linksys WUSB11v2.5 11Mbps USB WLAN Adapter"), 20 - PRISM_DEV(0x066b, 0x2213, "Linksys WUSB12v1.1 11Mbps USB WLAN Adapter"), 21 - PRISM_DEV(0x0411, 0x0016, "Melco WLI-USB-S11 11Mbps WLAN Adapter"), 22 - PRISM_DEV(0x08de, 0x7a01, "PRISM25 USB IEEE 802.11 Mini Adapter"), 23 - PRISM_DEV(0x8086, 0x1111, "Intel PRO/Wireless 2011B USB LAN Adapter"), 24 - PRISM_DEV(0x0d8e, 0x7a01, "PRISM25 IEEE 802.11 Mini USB Adapter"), 25 - PRISM_DEV(0x045e, 0x006e, "Microsoft MN510 USB Wireless Adapter"), 26 - PRISM_DEV(0x0967, 0x0204, "Acer Warplink USB Adapter"), 27 - PRISM_DEV(0x0cde, 0x0002, "Z-Com 725/726 Prism2.5 USB/USB Integrated"), 28 - PRISM_DEV(0x0cde, 0x0005, "Z-Com Xl735 USB Wireless 802.11b Adapter"), 29 - PRISM_DEV(0x413c, 0x8100, "Dell TrueMobile 1180 USB Wireless Adapter"), 30 - PRISM_DEV(0x0b3b, 0x1601, "ALLNET 0193 11Mbps USB WLAN Adapter"), 31 - PRISM_DEV(0x0b3b, 0x1602, "ZyXEL ZyAIR B200 USB Wireless Adapter"), 32 - PRISM_DEV(0x0baf, 0x00eb, "USRobotics USR1120 USB Wireless Adapter"), 33 - PRISM_DEV(0x0411, 0x0027, "Melco WLI-USB-KS11G 11Mbps WLAN Adapter"), 34 - PRISM_DEV(0x04f1, 0x3009, "JVC MP-XP7250 Builtin USB WLAN Adapter"), 35 - PRISM_DEV(0x0846, 0x4110, "NetGear MA111"), 36 - PRISM_DEV(0x03f3, 0x0020, "Adaptec AWN-8020 USB WLAN Adapter"), 37 - PRISM_DEV(0x2821, 0x3300, "ASUS-WL140 / Hawking HighDB USB Wireless Adapter"), 38 - PRISM_DEV(0x2001, 0x3700, "DWL-122 USB Wireless Adapter"), 39 - PRISM_DEV(0x2001, 0x3702, "DWL-120 Rev F USB Wireless Adapter"), 40 - PRISM_DEV(0x50c2, 0x4013, "Averatec USB WLAN Adapter"), 41 - PRISM_DEV(0x2c02, 0x14ea, "Planex GW-US11H USB WLAN Adapter"), 42 - PRISM_DEV(0x124a, 0x168b, "Airvast PRISM3 USB WLAN Adapter"), 43 - PRISM_DEV(0x083a, 0x3503, "T-Sinus 111 USB WLAN Adapter"), 44 - PRISM_DEV(0x0411, 0x0044, "Melco WLI-USB-KB11 11Mbps WLAN Adapter"), 45 - PRISM_DEV(0x1668, 0x6106, "ROPEX FreeLan USB 802.11b Adapter"), 46 - PRISM_DEV(0x124a, 0x4017, "Pheenet WL-503IA USB 802.11b Adapter"), 47 - PRISM_DEV(0x0bb2, 0x0302, "Ambit Microsystems Corp."), 48 - PRISM_DEV(0x9016, 0x182d, "Sitecom WL-022 USB 802.11b Adapter"), 49 - PRISM_DEV(0x0543, 0x0f01, 50 - "ViewSonic Airsync USB Adapter 11Mbps (Prism2.5)"), 51 - PRISM_DEV(0x067c, 0x1022, 52 - "Siemens SpeedStream 1022 11Mbps USB WLAN Adapter"), 53 - PRISM_DEV(0x049f, 0x0033, 54 - "Compaq/Intel W100 PRO/Wireless 11Mbps multiport WLAN Adapter"), 55 - { } /* terminator */ 56 - }; 57 - MODULE_DEVICE_TABLE(usb, usb_prism_tbl); 58 - 59 - static int prism2sta_probe_usb(struct usb_interface *interface, 60 - const struct usb_device_id *id) 61 - { 62 - struct usb_device *dev; 63 - struct usb_endpoint_descriptor *bulk_in, *bulk_out; 64 - struct usb_host_interface *iface_desc = interface->cur_altsetting; 65 - struct wlandevice *wlandev = NULL; 66 - struct hfa384x *hw = NULL; 67 - int result = 0; 68 - 69 - result = usb_find_common_endpoints(iface_desc, &bulk_in, &bulk_out, NULL, NULL); 70 - if (result) 71 - goto failed; 72 - 73 - dev = interface_to_usbdev(interface); 74 - wlandev = create_wlan(); 75 - if (!wlandev) { 76 - dev_err(&interface->dev, "Memory allocation failure.\n"); 77 - result = -EIO; 78 - goto failed; 79 - } 80 - hw = wlandev->priv; 81 - 82 - if (wlan_setup(wlandev, &interface->dev) != 0) { 83 - dev_err(&interface->dev, "wlan_setup() failed.\n"); 84 - result = -EIO; 85 - goto failed; 86 - } 87 - 88 - /* Initialize the hw data */ 89 - hw->endp_in = usb_rcvbulkpipe(dev, bulk_in->bEndpointAddress); 90 - hw->endp_out = usb_sndbulkpipe(dev, bulk_out->bEndpointAddress); 91 - hfa384x_create(hw, dev); 92 - hw->wlandev = wlandev; 93 - 94 - /* Register the wlandev, this gets us a name and registers the 95 - * linux netdevice. 96 - */ 97 - SET_NETDEV_DEV(wlandev->netdev, &interface->dev); 98 - 99 - /* Do a chip-level reset on the MAC */ 100 - if (prism2_doreset) { 101 - result = hfa384x_corereset(hw, 102 - prism2_reset_holdtime, 103 - prism2_reset_settletime, 0); 104 - if (result != 0) { 105 - result = -EIO; 106 - dev_err(&interface->dev, 107 - "hfa384x_corereset() failed.\n"); 108 - goto failed_reset; 109 - } 110 - } 111 - 112 - usb_get_dev(dev); 113 - 114 - wlandev->msdstate = WLAN_MSD_HWPRESENT; 115 - 116 - /* Try and load firmware, then enable card before we register */ 117 - prism2_fwtry(dev, wlandev); 118 - prism2sta_ifstate(wlandev, P80211ENUM_ifstate_enable); 119 - 120 - if (register_wlandev(wlandev) != 0) { 121 - dev_err(&interface->dev, "register_wlandev() failed.\n"); 122 - result = -EIO; 123 - goto failed_register; 124 - } 125 - 126 - goto done; 127 - 128 - failed_register: 129 - usb_put_dev(dev); 130 - failed_reset: 131 - wlan_unsetup(wlandev); 132 - failed: 133 - kfree(wlandev); 134 - kfree(hw); 135 - wlandev = NULL; 136 - 137 - done: 138 - usb_set_intfdata(interface, wlandev); 139 - return result; 140 - } 141 - 142 - static void prism2sta_disconnect_usb(struct usb_interface *interface) 143 - { 144 - struct wlandevice *wlandev; 145 - 146 - wlandev = usb_get_intfdata(interface); 147 - if (wlandev) { 148 - LIST_HEAD(cleanlist); 149 - struct hfa384x_usbctlx *ctlx, *temp; 150 - unsigned long flags; 151 - 152 - struct hfa384x *hw = wlandev->priv; 153 - 154 - if (!hw) 155 - goto exit; 156 - 157 - spin_lock_irqsave(&hw->ctlxq.lock, flags); 158 - 159 - p80211netdev_hwremoved(wlandev); 160 - list_splice_init(&hw->ctlxq.reapable, &cleanlist); 161 - list_splice_init(&hw->ctlxq.completing, &cleanlist); 162 - list_splice_init(&hw->ctlxq.pending, &cleanlist); 163 - list_splice_init(&hw->ctlxq.active, &cleanlist); 164 - 165 - spin_unlock_irqrestore(&hw->ctlxq.lock, flags); 166 - 167 - /* There's no hardware to shutdown, but the driver 168 - * might have some tasks that must be stopped before 169 - * we can tear everything down. 170 - */ 171 - prism2sta_ifstate(wlandev, P80211ENUM_ifstate_disable); 172 - 173 - timer_shutdown_sync(&hw->throttle); 174 - timer_shutdown_sync(&hw->reqtimer); 175 - timer_shutdown_sync(&hw->resptimer); 176 - 177 - /* Unlink all the URBs. This "removes the wheels" 178 - * from the entire CTLX handling mechanism. 179 - */ 180 - usb_kill_urb(&hw->rx_urb); 181 - usb_kill_urb(&hw->tx_urb); 182 - usb_kill_urb(&hw->ctlx_urb); 183 - 184 - cancel_work_sync(&hw->completion_bh); 185 - cancel_work_sync(&hw->reaper_bh); 186 - 187 - cancel_work_sync(&hw->link_bh); 188 - cancel_work_sync(&hw->commsqual_bh); 189 - cancel_work_sync(&hw->usb_work); 190 - 191 - /* Now we complete any outstanding commands 192 - * and tell everyone who is waiting for their 193 - * responses that we have shut down. 194 - */ 195 - list_for_each_entry(ctlx, &cleanlist, list) 196 - complete(&ctlx->done); 197 - 198 - /* Give any outstanding synchronous commands 199 - * a chance to complete. All they need to do 200 - * is "wake up", so that's easy. 201 - * (I'd like a better way to do this, really.) 202 - */ 203 - msleep(100); 204 - 205 - /* Now delete the CTLXs, because no-one else can now. */ 206 - list_for_each_entry_safe(ctlx, temp, &cleanlist, list) 207 - kfree(ctlx); 208 - 209 - /* Unhook the wlandev */ 210 - unregister_wlandev(wlandev); 211 - wlan_unsetup(wlandev); 212 - 213 - usb_put_dev(hw->usb); 214 - 215 - hfa384x_destroy(hw); 216 - kfree(hw); 217 - 218 - kfree(wlandev); 219 - } 220 - 221 - exit: 222 - usb_set_intfdata(interface, NULL); 223 - } 224 - 225 - #ifdef CONFIG_PM 226 - static int prism2sta_suspend(struct usb_interface *interface, 227 - pm_message_t message) 228 - { 229 - struct hfa384x *hw = NULL; 230 - struct wlandevice *wlandev; 231 - 232 - wlandev = usb_get_intfdata(interface); 233 - if (!wlandev) 234 - return -ENODEV; 235 - 236 - hw = wlandev->priv; 237 - if (!hw) 238 - return -ENODEV; 239 - 240 - prism2sta_ifstate(wlandev, P80211ENUM_ifstate_disable); 241 - 242 - usb_kill_urb(&hw->rx_urb); 243 - usb_kill_urb(&hw->tx_urb); 244 - usb_kill_urb(&hw->ctlx_urb); 245 - 246 - return 0; 247 - } 248 - 249 - static int prism2sta_resume(struct usb_interface *interface) 250 - { 251 - int result = 0; 252 - struct hfa384x *hw = NULL; 253 - struct wlandevice *wlandev; 254 - 255 - wlandev = usb_get_intfdata(interface); 256 - if (!wlandev) 257 - return -ENODEV; 258 - 259 - hw = wlandev->priv; 260 - if (!hw) 261 - return -ENODEV; 262 - 263 - /* Do a chip-level reset on the MAC */ 264 - if (prism2_doreset) { 265 - result = hfa384x_corereset(hw, 266 - prism2_reset_holdtime, 267 - prism2_reset_settletime, 0); 268 - if (result != 0) { 269 - unregister_wlandev(wlandev); 270 - hfa384x_destroy(hw); 271 - dev_err(&interface->dev, "hfa384x_corereset() failed.\n"); 272 - kfree(wlandev); 273 - kfree(hw); 274 - wlandev = NULL; 275 - return -ENODEV; 276 - } 277 - } 278 - 279 - prism2sta_ifstate(wlandev, P80211ENUM_ifstate_enable); 280 - 281 - return 0; 282 - } 283 - #else 284 - #define prism2sta_suspend NULL 285 - #define prism2sta_resume NULL 286 - #endif /* CONFIG_PM */ 287 - 288 - static struct usb_driver prism2_usb_driver = { 289 - .name = "prism2_usb", 290 - .probe = prism2sta_probe_usb, 291 - .disconnect = prism2sta_disconnect_usb, 292 - .id_table = usb_prism_tbl, 293 - .suspend = prism2sta_suspend, 294 - .resume = prism2sta_resume, 295 - .reset_resume = prism2sta_resume, 296 - /* fops, minor? */ 297 - }; 298 - 299 - module_usb_driver(prism2_usb_driver);