wl1251: prevent scan when connected
[pandora-wifi.git] / scripts / driver-select
1 #!/bin/bash
2 # Copyright 2009        Luis R. Rodriguez <mcgrof@gmail.com>
3 #
4 # This this to select your compat-wireless driver and
5 # reduce compilation time.
6
7 DRIVERS_MAKEFILE="drivers/net/wireless/Makefile"
8 ATH_MAKEFILE="drivers/net/wireless/ath/Makefile"
9 ATH9K_MAKEFILE="drivers/net/wireless/ath/ath9k/Makefile"
10 NET_WIRELESS_MAKEFILE="net/wireless/Makefile"
11 EEPROM_MAKEFILE="drivers/misc/eeprom/Makefile"
12 DRIVERS_NET="drivers/net/Makefile"
13 DRIVERS_NET_USB_MAKEFILE="drivers/net/usb/Makefile"
14 SSB_MAKEFILE="drivers/ssb/Makefile"
15
16 # used to backup files from foo to foo.${BACKUP_EXT}
17 # If you change this also modify restore_compat() and
18 # restore_file() below I couldn't find a way to use
19 # the $BACKUP_EXT there.
20 BACKUP_EXT="bk"
21
22 # Pretty colors
23 GREEN="\033[01;32m"
24 YELLOW="\033[01;33m"
25 NORMAL="\033[00m"
26 BLUE="\033[34m"
27 RED="\033[31m"
28 PURPLE="\033[35m"
29 CYAN="\033[36m"
30 UNDERLINE="\033[02m"
31
32 SUPPORTED_DRIVERS="ath5k ath9k ar9170 zd1211rw"
33
34 function usage {
35         echo -e "${GREEN}Usage${NORMAL}: ${CYAN}$0${NORMAL} [ ${PURPLE}<driver-name>${NORMAL} | ${PURPLE}<driver-group-name>${NORMAL} | ${GREEN}restore${NORMAL} ]"
36
37         # These should match the switch below.
38         echo -e "Supported drivers:"
39         for i in $SUPPORTED_DRIVERS; do
40                 echo -e "\t${PURPLE}${i}${NORMAL}"
41         done
42
43         # These should match the switch below.
44         echo -e "Supported group drivers:"
45         echo -e "\t${CYAN}atheros${NORMAL} < ${PURPLE} ath5k ath9k ar9170 zd1211rw ${NORMAL}>"
46         echo -e "\t${CYAN}ath${NORMAL} < ${PURPLE} ath5k ath9k ar9170 ${NORMAL}>"
47         echo -e "\t${CYAN}intel${NORMAL} < ${PURPLE} iwl3945 iwlagn ipw2100 ipw2200 ${NORMAL}>"
48         echo -e "\t${CYAN}iwlwifi${NORMAL} < ${PURPLE} iwl3945 iwlagn ${NORMAL}>"
49         echo -e "\t${CYAN}rtl818x${NORMAL} < ${PURPLE} rtl8180 rtl8187 ${NORMAL}>"
50         echo -e "\t${CYAN}wl12xx${NORMAL} < ${PURPLE} wl1251 (SPI and SDIO) wl1271 ${NORMAL}>"
51
52         echo -e "Restoring compat-wireless:"
53         echo -e "\t${GREEN}restore${NORMAL}: you can use this option to restore compat-wireless to the original state"
54 }
55
56 function backup_file {
57         if [ -f $1.${BACKUP_EXT} ]; then
58                 echo -e "Backup exists: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
59                 return
60         fi
61         echo -e "Backing up makefile: ${CYAN}${1}.${BACKUP_EXT}${NORMAL}"
62         cp $1 $1.bk
63 }
64
65 function disable_makefile
66 {
67         backup_file $1
68         echo > $1
69 }
70
71 function select_driver 
72 {
73         backup_file $DRIVERS_MAKEFILE
74         perl -i -ne 'print if /'$1'/ ' $DRIVERS_MAKEFILE
75 }
76
77 function select_drivers
78 {
79         backup_file $DRIVERS_MAKEFILE
80         CONFIGS=""
81         COUNT=0
82         for i in $@; do
83                 if [[ "$CONFIGS" = "" ]]; then
84                         CONFIGS="$i"
85                 else
86                         CONFIGS="${CONFIGS}|$i"
87                 fi
88         done
89         egrep "$CONFIGS" $DRIVERS_MAKEFILE > ${DRIVERS_MAKEFILE}.tmp
90         mv ${DRIVERS_MAKEFILE}.tmp ${DRIVERS_MAKEFILE}
91 }
92
93 function disable_lib80211
94 {
95         backup_file $NET_WIRELESS_MAKEFILE
96         perl -i -ne 'print if ! /LIB80211/ ' $NET_WIRELESS_MAKEFILE
97 }
98
99 function disable_b44 {
100         backup_file $DRIVERS_NET
101         perl -i -ne 'print if ! /CONFIG_B44/ ' $DRIVERS_NET
102 }
103
104 function disable_ssb
105 {
106         disable_b44
107         disable_makefile ${SSB_MAKEFILE}
108         perl -i -ne 'print if ! /drivers\/ssb\/ \\/ ' Makefile
109 }
110
111 function disable_eeprom
112 {
113         disable_makefile ${EEPROM_MAKEFILE}
114         perl -i -ne 'print if ! /drivers\/misc\/eeprom\/ \\/' Makefile
115 }
116
117 function disable_usbnet
118 {
119         disable_makefile ${DRIVERS_NET_USB_MAKEFILE}
120         perl -i -ne 'print if ! /drivers\/net\/usb\/ \\/' Makefile
121 }
122
123 function disable_usbnet {
124         perl -i -ne 'print if ! /CONFIG_COMPAT_NET_USB_MODULES/' Makefile
125
126
127 function disable_ethernet {
128         perl -i -ne 'print if ! /CONFIG_COMPAT_NETWORK_MODULES/' Makefile
129
130
131 function disable_var_03 {
132         perl -i -ne 'print if ! /CONFIG_COMPAT_BLUETOOTH/' Makefile
133
134
135 function disable_bt {
136         perl -i -ne 'print if ! /CONFIG_COMPAT_VAR_MODULES/' Makefile
137
138
139 function disable_bt_usb_ethernet_var {
140         backup_file Makefile
141         disable_usbnet
142         disable_ethernet
143         disable_var_03
144         disable_bt
145
146
147 function disable_var {
148         disable_ssb
149         disable_usbnet
150         disable_eeprom
151
152
153 function disable_var_01 {
154         disable_lib80211
155         disable_var
156 }
157
158 function disable_var_02 {
159         #var_01 with eeprom not disabled
160         disable_lib80211
161         disable_ssb
162         disable_usbnet
163 }
164
165 function select_ath_driver 
166 {
167         backup_file $ATH_MAKEFILE
168         perl -i -ne 'print if /'$1'/ || /CONFIG_ATH_/ || /ath-objs/ || /regd.o/ || /hw.o/ ' $ATH_MAKEFILE
169         disable_var_01
170 }
171
172 function select_ath9k_driver
173 {
174         select_ath_driver CONFIG_ATH9K_HW
175         # In the future here we'll add stuff to disable ath9k_htc
176 }
177
178 # iwlwifi stuff needs more work
179 function select_iwl_driver 
180 {
181         perl -i -ne 'print if /'$1'/ || /CONFIG_BLEH/ ' drivers/net/wireless/iwlwifi/Makefile
182         disable_var_01
183 }
184
185 function restore_file {
186         #ORIG=$(shell ${1%%.${BACKUP_EXT}})
187         ORIG=${1%%.bk}
188         cp $1 $ORIG
189         rm -f $1
190         echo -e "Restored makefile: ${CYAN}${ORIG}${NORMAL} (and removed backup)"
191 }
192
193 function restore_compat {
194         #FILES=$(find ./ -type f -name *.$BACKUP_EXT)
195         FILES=$(find ./ -type f -name *.bk)
196         for i in $FILES; do
197                 restore_file $i
198         done
199 }
200
201 if [ $# -ne 1 ]; then
202         usage
203         exit
204 fi
205
206 if [ ! -f compat-release ]; then
207         echo "Must run $0 from the compat-wireless top level directory"
208         exit
209 fi
210
211 if [[ ! -f built-in.o ]]; then
212         if [[ "$1" != "restore" ]]; then
213                 echo -e "${YELLOW}Processing new driver-select request...${NORMAL}"
214         fi
215 fi
216
217 # Always backup the top level Makefile, unless restoring
218 if [[ "$1" != "restore" ]]; then
219         backup_file Makefile
220 fi
221
222 # If a user selects a new driver make sure we clean up for them
223 # first and also restore the backup makefiles then. Otherwise
224 # we'll be trying to leave drivers on Makefiles which are not
225 # already there from a previous run.
226 if [ -f built-in.o ]; then
227         echo -e "${YELLOW}Old build found, going to clean this up first...${NORMAL}"
228         make clean
229         echo -e "${YELLOW}Restoring Makefiles...${NORMAL}"
230         ./$0 restore
231 fi
232
233 case $1 in
234         restore)
235                 restore_compat
236                 ;;
237         atheros)
238                 select_drivers          CONFIG_ATH_COMMON \
239                                         CONFIG_ZD1211RW
240                 disable_var_01
241                 ;;
242         ath)
243                 disable_bt_usb_ethernet_var
244                 select_drivers          CONFIG_ATH_COMMON
245                 disable_var_01
246                 ;;
247         intel)
248                 select_drivers          CONFIG_IWLWIFI \
249                                         CONFIG_IPW
250                 disable_var
251                 ;;
252         iwlwifi)
253                 select_driver           CONFIG_IWLWIFI
254                 disable_var_01
255                 ;;
256         wl12xx)
257                 select_drivers          CONFIG_WL12XX
258                 disable_var_01
259                 ;;
260         ath5k)
261                 disable_bt_usb_ethernet_var
262                 select_driver           CONFIG_ATH_COMMON
263                 select_ath_driver       CONFIG_ATH5K
264                 #patch -p1 < enable-older-kernels/enable-2.6.23.patch
265                 ;;
266         ath9k)
267                 disable_bt_usb_ethernet_var
268                 select_driver           CONFIG_ATH_COMMON
269                 select_ath9k_driver
270                 #patch -p1 < enable-older-kernels/enable-2.6.23.patch
271                 ;;
272         ar9170)
273                 disable_bt_usb_ethernet_var
274                 select_driver           CONFIG_ATH_COMMON
275                 select_ath_driver       CONFIG_AR9170_USB
276                 ;;
277         rtl818x)
278                 select_drivers          CONFIG_RTL8180 CONFIG_RTL8187
279                 disable_var_02
280                 ;;
281         zd1211rw)
282                 select_driver           CONFIG_ZD1211RW
283                 disable_var_01
284                 ;;
285         *)
286                 echo "Unsupported driver"
287                 exit
288                 ;;
289 esac