| 1 | /* |
|---|
| 2 | * wireless.c |
|---|
| 3 | * |
|---|
| 4 | * Copyright (C) 2009 Sebastian Gottschall <gottschall@dd-wrt.com> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or |
|---|
| 7 | * modify it under the terms of the GNU General Public License |
|---|
| 8 | * as published by the Free Software Foundation; either version 2 |
|---|
| 9 | * of the License, or (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | * |
|---|
| 20 | * $Id: |
|---|
| 21 | * |
|---|
| 22 | * detects atheros wireless adapters and loads the drivers |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | // extern int getath9kdevicecount(void); |
|---|
| 26 | extern void delete_ath9k_devices(char *physical_iface); |
|---|
| 27 | |
|---|
| 28 | static void setWirelessLed(int phynum, int ledpin) |
|---|
| 29 | { |
|---|
| 30 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 31 | int triggergpio = ledpin; |
|---|
| 32 | #endif |
|---|
| 33 | #ifdef HAVE_ATH9K |
|---|
| 34 | char trigger[32]; |
|---|
| 35 | char sysname[32]; |
|---|
| 36 | sprintf(trigger, "phy%dtpt", phynum); |
|---|
| 37 | if (ledpin < 32) { |
|---|
| 38 | sprintf(sysname, "generic_%d", ledpin); |
|---|
| 39 | } else { |
|---|
| 40 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 41 | if (ledpin < 48) |
|---|
| 42 | triggergpio = ledpin - 32; |
|---|
| 43 | else |
|---|
| 44 | triggergpio = ledpin - 48; |
|---|
| 45 | #endif |
|---|
| 46 | sprintf(sysname, "wireless_generic_%d", ledpin - 32); |
|---|
| 47 | } |
|---|
| 48 | sysprintf("echo %s > /sys/devices/platform/leds-gpio/leds/%s/trigger", |
|---|
| 49 | trigger, sysname); |
|---|
| 50 | #else |
|---|
| 51 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 52 | if (ledpin >= 32) { |
|---|
| 53 | if (ledpin < 48) |
|---|
| 54 | triggergpio = ledpin - 32; |
|---|
| 55 | else |
|---|
| 56 | triggergpio = ledpin - 48; |
|---|
| 57 | } |
|---|
| 58 | #endif |
|---|
| 59 | #endif |
|---|
| 60 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 61 | sysprintf("echo %d >/proc/sys/dev/wifi%d/ledpin", triggergpio, phynum); |
|---|
| 62 | sysprintf("echo 1 >/proc/sys/dev/wifi%d/softled", phynum); |
|---|
| 63 | #endif |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | #define setWirelessLedGeneric(a,b) setWirelessLed(a,b) |
|---|
| 67 | #define setWirelessLedPhy0(b) setWirelessLed(0,b+32) |
|---|
| 68 | #define setWirelessLedPhy1(b) setWirelessLed(1,b+48) |
|---|
| 69 | |
|---|
| 70 | static void detect_wireless_devices(void) |
|---|
| 71 | { |
|---|
| 72 | #ifdef HAVE_RT61 |
|---|
| 73 | FILE *fp = fopen("/sys/bus/pci/devices/0000:00:0e.0/device", "rb"); |
|---|
| 74 | if (fp) { |
|---|
| 75 | char str[32]; |
|---|
| 76 | fscanf(fp, "%s", str); |
|---|
| 77 | fclose(fp); |
|---|
| 78 | if (!strcmp(str, "0x3592")) |
|---|
| 79 | nvram_set("rtchip", "3062"); |
|---|
| 80 | else |
|---|
| 81 | nvram_set("rtchip", "2860"); |
|---|
| 82 | } else |
|---|
| 83 | nvram_set("rtchip", "2860"); |
|---|
| 84 | |
|---|
| 85 | #endif |
|---|
| 86 | #ifndef HAVE_NOWIFI |
|---|
| 87 | nvram_default_get("rate_control", "minstrel"); |
|---|
| 88 | #ifdef HAVE_MADWIFI |
|---|
| 89 | fprintf(stderr, "load ATH 802.11 a/b/g Driver\n"); |
|---|
| 90 | insmod("ath_hal"); |
|---|
| 91 | if (nvram_get("rate_control") != NULL) { |
|---|
| 92 | char rate[64]; |
|---|
| 93 | |
|---|
| 94 | sprintf(rate, "ratectl=%s", nvram_safe_get("rate_control")); |
|---|
| 95 | eval("insmod", "ath_pci", rate); |
|---|
| 96 | eval("insmod", "ath_ahb", rate); |
|---|
| 97 | } else { |
|---|
| 98 | insmod("ath_pci"); |
|---|
| 99 | insmod("ath_ahb"); |
|---|
| 100 | } |
|---|
| 101 | #ifdef HAVE_ATH9K |
|---|
| 102 | #ifndef HAVE_MADWIFI_MIMO |
|---|
| 103 | if (1) |
|---|
| 104 | #else |
|---|
| 105 | if (nvram_match("mimo_driver", "ath9k")) |
|---|
| 106 | #endif |
|---|
| 107 | { |
|---|
| 108 | fprintf(stderr, "load ATH9K 802.11n Driver\n"); |
|---|
| 109 | // some are just for future use and not (yet) there |
|---|
| 110 | insmod("/lib/ath9k/compat.ko"); |
|---|
| 111 | insmod("/lib/ath9k/compat_firmware_class.ko"); |
|---|
| 112 | insmod("/lib/ath9k/cfg80211.ko"); |
|---|
| 113 | insmod("/lib/ath9k/mac80211.ko"); |
|---|
| 114 | insmod("/lib/ath9k/ath.ko"); |
|---|
| 115 | insmod("/lib/ath9k/ath9k_hw.ko"); |
|---|
| 116 | insmod("/lib/ath9k/ath9k_common.ko"); |
|---|
| 117 | #ifdef HAVE_WZRG450 |
|---|
| 118 | system("/sbin/insmod /lib/ath9k/ath9k.ko blink=1"); |
|---|
| 119 | #else |
|---|
| 120 | insmod("/lib/ath9k/ath9k.ko"); |
|---|
| 121 | #endif |
|---|
| 122 | delete_ath9k_devices(NULL); |
|---|
| 123 | } else { |
|---|
| 124 | #endif |
|---|
| 125 | #ifdef HAVE_MADWIFI_MIMO |
|---|
| 126 | fprintf(stderr, "load ATH 802.11n Driver\n"); |
|---|
| 127 | insmod("/lib/80211n/ath_mimo_hal.ko"); |
|---|
| 128 | if (nvram_get("rate_control") != NULL) { |
|---|
| 129 | char rate[64]; |
|---|
| 130 | |
|---|
| 131 | sprintf(rate, "ratectl=%s", |
|---|
| 132 | nvram_safe_get("rate_control")); |
|---|
| 133 | insmod("/lib/80211n/ath_mimo_pci.ko"); |
|---|
| 134 | insmod("/lib/80211n/ath_mimo_ahb.ko"); |
|---|
| 135 | } else { |
|---|
| 136 | insmod("/lib/80211n/ath_mimo_pci.ko"); |
|---|
| 137 | insmod("/lib/80211n/ath_mimo_ahb.ko"); |
|---|
| 138 | } |
|---|
| 139 | #endif |
|---|
| 140 | #ifdef HAVE_ATH9K |
|---|
| 141 | } |
|---|
| 142 | #endif |
|---|
| 143 | #endif |
|---|
| 144 | #endif |
|---|
| 145 | } |
|---|