airmon-ng 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  1. #!/bin/sh
  2. DEBUG="0"
  3. VERBOSE="0"
  4. ELITE="0"
  5. USERID=""
  6. IFACE=""
  7. checkvm_status=""
  8. MAC80211=0
  9. IW_SOURCE="https://mirrors.edge.kernel.org/pub/software/network/iw/iw-5.0.1.tar.gz"
  10. IW_ERROR=""
  11. if [ ! -d /sys/ ]; then
  12. printf "CONFIG_SYSFS is disabled in your kernel, this program will almost certainly not work.\n"
  13. fi
  14. if [ "${1}" = "--elite" ]; then
  15. shift
  16. ELITE="1"
  17. fi
  18. if [ "${1}" = "--verbose" ]; then
  19. shift
  20. VERBOSE="1"
  21. fi
  22. if [ "${1}" = "--debug" ]; then
  23. shift
  24. DEBUG="1"
  25. VERBOSE="1"
  26. fi
  27. #yes, I know this is in here twice
  28. if [ "${1}" = "--elite" ]; then
  29. shift
  30. ELITE="1"
  31. fi
  32. if [ -n "${3}" ];then
  33. if [ "${3}" -gt 0 ] > /dev/null 2>&1; then
  34. CH="${3}"
  35. else
  36. printf "\nYou have entered an invalid channel \"${3}\" which will be ignored\n"
  37. CH=3
  38. fi
  39. else
  40. CH=10
  41. fi
  42. #TODO LIST
  43. #cleanup getDriver()
  44. #fix to not assume wifi drivers are modules
  45. #rewrite to not have two devices at any one time
  46. if [ -n "$(command -v id 2> /dev/null)" ]; then
  47. USERID="$(id -u 2> /dev/null)"
  48. fi
  49. if [ -z "${USERID}" ] && [ -n "$(id -ru)" ]; then
  50. USERID="$(id -ru)"
  51. fi
  52. if [ -n "${USERID}" ] && [ "${USERID}" != "0" ]; then
  53. printf "Run it as root\n" ; exit 1;
  54. elif [ -z "${USERID}" ]; then
  55. printf "Unable to determine user id, permission errors may occur.\n"
  56. fi
  57. #check for all needed binaries
  58. if [ ! -x "$(command -v uname 2>&1)" ]; then
  59. printf "How in the world do you not have uname installed?\n"
  60. printf "Please select a linux distro which has at least basic functionality (or install uname).\n"
  61. exit 1
  62. else
  63. OS=$(uname -s)
  64. #Recognized values are Linux and Darwin
  65. fi
  66. if [ ! -x "$(command -v ip 2>&1)" ] && [ ! -x "$(command -v ifconfig 2>&1)" ]; then
  67. printf "You have neither ip (iproute2) nor ifconfig installed.\n"
  68. printf "Please install one of them from your distro's package manager.\n"
  69. exit 1
  70. fi
  71. if [ ! -x "$(command -v iw 2>&1)" ]; then
  72. printf "You don't have iw installed, please install it from your distro's package manager.\n"
  73. printf "If your distro doesn't have a recent version you can download it from this link:\n"
  74. printf "${IW_SOURCE}\n"
  75. exit 1
  76. fi
  77. if [ ! -x "$(command -v ethtool 2>&1)" ]; then
  78. printf "Please install the ethtool package for your distro.\n"
  79. exit 1
  80. fi
  81. if [ -d /sys/bus/usb ]; then
  82. if [ ! -x "$(command -v lsusb 2>&1)" ]; then
  83. printf "Please install lsusb from your distro's package manager.\n"
  84. exit 1
  85. else
  86. LSUSB=1
  87. fi
  88. else
  89. LSUSB=0
  90. fi
  91. LSPCI=0
  92. # if [ -d /sys/bus/pci ] || [ -d /sys/bus/pci_express ] || [ -d /proc/bus/pci ]; then
  93. # PCI_DEVICES=0
  94. # if [ -d /sys/bus/pci/devices ] && [ "$(ls -1 /sys/bus/pci/devices 2>/dev/null | wc -l)" != '0' ]; then
  95. # PCI_DEVICES=1
  96. # elif [ -r /proc/bus/pci/devices ] && [ -n "$(cat /proc/bus/pci/devices 2>/dev/null)" ]; then
  97. # PCI_DEVICES=1
  98. # elif [ -d /sys/bus/pci_express/devices ] && [ -n "$(ls -1 /sys/bus/pci_express/devices 2>/dev/null | wc -l)" != '0' ]; then
  99. # PCI_DEVICES=1
  100. # fi
  101. # if [ ${PCI_DEVICES} -eq 0 ]; then
  102. # LSPCI=0
  103. # elif [ ! -x "$(command -v lspci 2>&1)" ]; then
  104. # printf "Please install lspci from your distro's package manager.\n"
  105. # exit 1
  106. # else
  107. # LSPCI=1
  108. # fi
  109. # else
  110. # LSPCI=0
  111. # fi
  112. if [ -f /proc/modules ] || [ -d /sys/module ]; then
  113. if [ ! -x "$(command -v modprobe 2>&1)" ]; then
  114. printf "Your kernel has module support but you don't have modprobe installed.\n"
  115. printf "It is highly recommended to install modprobe (typically from kmod).\n"
  116. MODPROBE=0
  117. else
  118. MODPROBE=1
  119. fi
  120. if [ ! -x "$(command -v modinfo 2>&1)" ]; then
  121. printf "Your kernel has module support but you don't have modinfo installed.\n"
  122. printf "It is highly recommended to install modinfo (typically from kmod).\n"
  123. printf "Warning: driver detection without modinfo may yield inaccurate results.\n"
  124. MODINFO=0
  125. else
  126. MODINFO=1
  127. fi
  128. else
  129. MODINFO=0
  130. fi
  131. if [ -c /dev/rfkill ]; then
  132. if [ ! -x "$(command -v rfkill 2>&1)" ];then
  133. printf "Your kernel supports rfkill but you don't have rfkill installed.\n"
  134. printf "To ensure devices are unblocked you must install rfkill.\n"
  135. RFKILL=0
  136. else
  137. RFKILL=1
  138. fi
  139. else
  140. RFKILL=0
  141. fi
  142. if [ ! -x "$(command -v awk 2>&1)" ]; then
  143. printf "How in the world do you not have awk installed?\n"
  144. printf "Please select a linux distro which has at least basic functionality (or install awk).\n"
  145. exit 1
  146. fi
  147. if [ ! -x "$(command -v grep 2>&1)" ]; then
  148. printf "How in the world do you not have grep installed?\n"
  149. printf "Please select a linux distro which has at least basic functionality (or install grep).\n"
  150. exit 1
  151. fi
  152. #done checking for binaries
  153. usage() {
  154. printf "usage: $(basename $0) <start|stop|check> <interface> [channel or frequency]\n\n"
  155. exit 0
  156. }
  157. handleLostPhys() {
  158. MISSING_INTERFACE=""
  159. if [ -d /sys/class/ieee80211 ]; then
  160. for i in $(ls /sys/class/ieee80211/); do
  161. if [ ! -d /sys/class/ieee80211/${i}/device/net ]; then
  162. MISSING_INTERFACE="${i}"
  163. printf "\nFound ${MISSING_INTERFACE} with no interfaces assigned, would you like to assign one to it? [y/n] "
  164. yesorno
  165. retcode=$?
  166. if [ "${retcode}" = "1" ]; then
  167. printf "PHY ${MISSING_INTERFACE} will remain lost.\n"
  168. elif [ "${retcode}" = "0" ]; then
  169. PHYDEV=${MISSING_INTERFACE}
  170. findFreeInterface monitor
  171. fi
  172. fi
  173. done
  174. fi
  175. #add some spacing so this doesn't make the display hard to read
  176. printf "\n"
  177. }
  178. findFreeInterface() {
  179. if [ -z "${1}" ]; then
  180. printf "findFreeInterface needs a target mode.\n"
  181. exit 1
  182. fi
  183. if [ "${1}" != "monitor" ] && [ "${1}" != "station" ]; then
  184. printf "findFreeInterface only supports monitor and station for target mode.\n"
  185. exit 1
  186. fi
  187. target_mode="${1}"
  188. if [ "$target_mode" = "monitor" ]; then
  189. target_suffix="mon"
  190. target_type="803"
  191. else
  192. target_suffix=""
  193. target_type="1"
  194. fi
  195. for i in $(seq 0 100); do
  196. if [ "$i" = "100" ]; then
  197. printf "\n\tUnable to find a free name between wlan0 and wlan99, you are on your own from here.\n"
  198. return 1
  199. fi
  200. if [ "$DEBUG" = "1" ]; then
  201. printf "\nChecking candidate wlan${i}\n"
  202. fi
  203. if [ ! -e /sys/class/net/wlan${i} ]; then
  204. if [ "$DEBUG" = "1" ]; then
  205. printf "\nCandidate wlan${i} is not in use\n"
  206. fi
  207. if [ ! -e /sys/class/net/wlan${i}mon ]; then
  208. if [ "$DEBUG" = "1" ]; then
  209. printf "\nCandidate wlan${i} and wlan${i}mon are both clear, creating wlan${i}${target_suffix}\n"
  210. fi
  211. IW_ERROR="$(iw phy ${PHYDEV} interface add wlan${i}${target_suffix} type ${target_mode} 2>&1)"
  212. if [ -z "${IW_ERROR}" ]; then
  213. if [ -d /sys/class/ieee80211/${PHYDEV}/device/net ]; then
  214. for j in $(ls /sys/class/ieee80211/${PHYDEV}/device/net/); do
  215. if [ "$(cat /sys/class/ieee80211/${PHYDEV}/device/net/${j}/type)" = "${target_type}" ]; then
  216. #here is where we catch udev renaming our interface
  217. k=${j#wlan}
  218. i=${k%mon}
  219. fi
  220. done
  221. else
  222. printf "Unable to create wlan${i}${target_suffix} and no error received.\n"
  223. return 1
  224. fi
  225. printf "\n\t\t(mac80211 ${target_mode} mode vif enabled on [${PHYDEV}]wlan${i}${target_suffix}\n"
  226. unset IW_ERROR
  227. break
  228. else
  229. printf "\n\n ERROR adding ${target_mode} mode interface: ${IW_ERROR}\n"
  230. break
  231. fi
  232. else
  233. if [ "$DEBUG" = "1" ]; then
  234. printf "\nCandidate wlan${i} does not exist, but wlan${i}mon does, skipping...\n"
  235. fi
  236. fi
  237. else
  238. if [ "$DEBUG" = "1" ]; then
  239. printf "\nCandidate wlan${i} is in use already.\n"
  240. fi
  241. fi
  242. done
  243. }
  244. rfkill_check() {
  245. #take phy and check blocks
  246. if [ "${RFKILL}" = 0 ]; then
  247. #immediately return if rfkill isn't supported
  248. return 0
  249. fi
  250. if [ -z "${1}" ]; then
  251. printf "Fatal, rfkill_check requires a phy to be passed in\n"
  252. exit 1
  253. fi
  254. #first we have to find the rfkill index
  255. #this is available as /sys/class/net/wlan0/phy80211/rfkill## but that's a bit difficult to parse
  256. index="$(rfkill list | grep "${1}:" | awk -F: '{print $1}')"
  257. if [ -z "$index" ]; then
  258. return 187
  259. fi
  260. rfkill_status="$(rfkill list ${index} 2>&1)"
  261. if [ $? != 0 ]; then
  262. printf "rfkill error: ${rfkill_status}\n"
  263. return 187
  264. elif [ -z "${rfkill_status}" ]; then
  265. printf "rfkill had no output, something went wrong.\n"
  266. exit 1
  267. else
  268. soft=$(printf "${rfkill_status}" | grep -i soft | awk '{print $3}')
  269. hard=$(printf "${rfkill_status}" | grep -i hard | awk '{print $3}')
  270. if [ "${soft}" = "yes" ] && [ "${hard}" = "no" ]; then
  271. return 1
  272. elif [ "${soft}" = "no" ] && [ "${hard}" = "yes" ]; then
  273. return 2
  274. elif [ "${soft}" = "yes" ] && [ "${hard}" = "yes" ]; then
  275. return 3
  276. fi
  277. fi
  278. return 0
  279. }
  280. rfkill_unblock() {
  281. #attempt unblock and CHECK SUCCESS
  282. if [ "${RFKILL}" = 0 ]; then
  283. #immediately return if rfkill isn't supported
  284. return 0
  285. fi
  286. rfkill_status="$(rfkill unblock ${1#phy} 2>&1)"
  287. if [ $? != 0 ]; then
  288. rfkill_status="$(rfkill unblock $index 2>&1)"
  289. if [ $? != 0 ]; then
  290. if [ `echo "$blah" | grep "Usage" | wc -l` -eq 1 ]; then
  291. printf "Missing parameters in rfkill! Report this"
  292. else
  293. printf "rfkill error: ${rfkill_status}\n"
  294. fi
  295. printf "Unable to unblock.\n"
  296. return 1
  297. fi
  298. fi
  299. sleep 1
  300. return 0
  301. }
  302. setLink() {
  303. if [ -x "$(command -v ip 2>&1)" ]; then
  304. ip link set dev ${1} ${2} > /dev/null 2>&1 || printf "\nFailed to set ${1} ${2} using ip\n"
  305. elif [ -x "$(command -v ifconfig 2>&1)" ]; then
  306. ifconfig ${1} ${2} > /dev/null 2>&1 || printf "\nFailed to set ${1} ${2} using ifconfig\n"
  307. fi
  308. return
  309. }
  310. ifaceIsUp() {
  311. if [ -x "$(command -v ip 2>&1)" ]; then
  312. ifaceIsUpCmd="ip link show dev"
  313. elif [ -x "$(command -v ifconfig 2>&1)" ]; then
  314. ifaceIsUpCmd="ifconfig"
  315. fi
  316. if ${ifaceIsUpCmd} ${1} 2>&1 | grep -q UP
  317. then
  318. return
  319. else
  320. return 1
  321. fi
  322. }
  323. #listIfaceUnspec() {
  324. # if [ -x "$(command -v ip 2>&1)" ]; then
  325. # ip link 2>/dev/null | awk -F"[: ]+" '/UNSPEC/ {print $2}'
  326. # elif [ -x "$(command -v ifconfig 2>&1)" ]; then
  327. # ifconfig -a 2>/dev/null | awk -F"[: ]+" '/UNSPEC/ {print $1}'
  328. # fi
  329. #}
  330. startDeprecatedIface() {
  331. iwconfig ${1} mode monitor > /dev/null 2>&1
  332. if [ -n "${2}" ]; then
  333. if [ ${2} -lt 1000 ]; then
  334. iwconfig ${1} channel ${2} > /dev/null 2>&1
  335. else
  336. iwconfig ${1} freq ${2}000000 > /dev/null 2>&1
  337. fi
  338. else
  339. iwconfig ${1} channel ${CH} > /dev/null 2>&1
  340. fi
  341. iwconfig ${1} key off > /dev/null 2>&1
  342. setLink ${1} up
  343. printf " (monitor mode enabled)"
  344. }
  345. yesorno() {
  346. read input
  347. case $input in
  348. y) return 0 ;;
  349. yes) return 0 ;;
  350. n) return 1 ;;
  351. no) return 1 ;;
  352. *) printf "\nInvalid input. Yes, or no? [y/n] "
  353. yesorno;;
  354. esac
  355. }
  356. startMac80211Iface() {
  357. #check if rfkill is set and cry if it is
  358. rfkill_check ${PHYDEV}
  359. rfkill_retcode="$?"
  360. case ${rfkill_retcode} in
  361. 1) printf "\t${1} is soft blocked, please run \"rfkill unblock ${index}\" to use this interface.\n" ;;
  362. 2) printf "\t${1} is hard blocked, please flip the hardware wifi switch (or in BIOS) to on.\n"
  363. printf "\tIt may also be possible to unblock with \"rfkill unblock ${index}\"\n"
  364. if [ "${checkvm_status}" != "run" ]; then
  365. checkvm
  366. fi
  367. if [ -n "${vm}" ]; then
  368. printf "Detected VM using ${vm_from}\n"
  369. printf "This appears to be a ${vm} Virtual Machine\n"
  370. printf "Some distributions have bugs causing rfkill hard block to be forced on in a VM.\n"
  371. printf "If toggling the rfkill hardware switch and \"rfkill unblock ${index}\" both fail\n"
  372. printf "to fix this, please try not running in a VM.\n"
  373. fi
  374. ;;
  375. 3) printf "\t${1} is hard and soft blocked, please flip the hardware wifi switch to on.\n"
  376. printf "\tIt may also be needed to unblock with \"rfkill unblock ${index}\"\n" ;;
  377. esac
  378. if [ "${rfkill_retcode}" != 0 ]; then
  379. printf "rfkill error, unable to start ${1}\n\n"
  380. printf "Would you like to try and automatically resolve this? [y/n] "
  381. yesorno
  382. retcode="$?"
  383. if [ "${retcode}" = "1" ]; then
  384. return 1
  385. elif [ "${retcode}" = "0" ]; then
  386. rfkill_unblock ${PHYDEV}
  387. fi
  388. fi
  389. #check if $1 already has a mon interface on the same phy and bail if it does
  390. if [ -d /sys/class/ieee80211/${PHYDEV}/device/net ]; then
  391. for i in $(ls /sys/class/ieee80211/${PHYDEV}/device/net/); do
  392. if [ "$(cat /sys/class/ieee80211/${PHYDEV}/device/net/${i}/type)" = "803" ]; then
  393. setChannelMac80211 ${i}
  394. printf "\n\t\t(mac80211 monitor mode already enabled for [${PHYDEV}]${1} on [${PHYDEV}]${i})\n"
  395. exit
  396. fi
  397. done
  398. fi
  399. #we didn't bail means we need a monitor interface
  400. if [ ${#1} -gt 12 ]; then
  401. printf "Interface ${1}mon is too long for linux so it will be renamed to the old style (wlan#) name.\n"
  402. findFreeInterface monitor
  403. else
  404. if [ -e /sys/class/net/${1}mon ]; then
  405. printf "\nYou already have a ${1}mon device but it is NOT in monitor mode."
  406. printf "\nWhatever you did, don't do it again."
  407. printf "\nPlease run \"iw ${1}mon del\" before attempting to continue\n"
  408. exit 1
  409. fi
  410. #we didn't bail means our target interface is available
  411. setLink ${1} down
  412. if [ "${DRIVER}" = "8812au" ] || [ "${DRIVER}" = "8814au" ] || [ "${DRIVER}" = "88XXau" ]; then
  413. #grumble grumble, seriously crap vendor driver
  414. startDeprecatedIface ${1}
  415. setChannelMac80211 ${1}
  416. return
  417. fi
  418. IW_ERROR="$(iw phy ${PHYDEV} interface add ${1}mon type monitor 2>&1)"
  419. if [ -z "${IW_ERROR}" ]; then
  420. sleep 1
  421. if [ -r "/sys/class/ieee80211/${PHYDEV}/device/net/${1}mon/type" ] && [ "$(cat /sys/class/ieee80211/${PHYDEV}/device/net/${1}mon/type)" = "803" ]; then
  422. setChannelMac80211 ${1}mon
  423. else
  424. printf "\nNewly created monitor mode interface ${1}mon is *NOT* in monitor mode.\n"
  425. printf "Removing non-monitor ${1}mon interface...\n"
  426. stopMac80211Iface ${1}mon abort
  427. exit 1
  428. fi
  429. printf "\n\t\t(mac80211 monitor mode vif enabled for [${PHYDEV}]${1} on [${PHYDEV}]${1}mon)\n"
  430. else
  431. printf "\n\nERROR adding monitor mode interface: ${IW_ERROR}\n"
  432. exit 1
  433. fi
  434. fi
  435. if [ "${ELITE}" = "1" ]; then
  436. #check if $1 is still down, warn if not
  437. if ifaceIsUp ${1}
  438. then
  439. printf "\nInterface ${1} is up, but it should be down. Something is interfering."
  440. printf "\nPlease run \"airmon-ng check kill\" and/or kill your network manager."
  441. fi
  442. else
  443. isRPiWireless && iw ${1} del
  444. printf "\t\t(mac80211 station mode vif disabled for [${PHYDEV}]${1})\n"
  445. fi
  446. }
  447. isRPiWireless() {
  448. local HW_REV=$(grep Revision /proc/cpuinfo | awk '{print $3}')
  449. [ -z "${HW_REV}" ] && return 0
  450. # http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/
  451. # https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md
  452. [ "${HW_REV}" = 'a22082' ] && return 1
  453. [ "${HW_REV}" = 'a32082' ] && return 1
  454. [ "${HW_REV}" = 'a52082' ] && return 1
  455. [ "${HW_REV}" = 'a02082' ] && return 1
  456. [ "${HW_REV}" = '9000c1' ] && return 1
  457. [ "${HW_REV}" = 'a020d3' ] && return 1
  458. [ "${HW_REV}" = '9020e0' ] && return 1
  459. return 0
  460. }
  461. startwlIface() {
  462. if [ -f "/proc/brcm_monitor0" ]; then
  463. if [ -r "/proc/brcm_monitor0" ]; then
  464. local brcm_monitor="$(cat /proc/brcm_monitor0)"
  465. if [ "$brcm_monitor" = "1" ]; then
  466. printf "\n\t\t(experimental wl monitor mode vif already enabled for [${PHYDEV}]${1} on [${PHYDEV}]prism0)\n"
  467. return 0
  468. fi
  469. fi
  470. if [ -w "/proc/brcm_monitor0" ]; then
  471. printf "1" > /proc/brcm_monitor0
  472. if [ "$?" = "0" ]; then
  473. printf "\n\t\t(experimental wl monitor mode vif enabled for [${PHYDEV}]${1} on [${PHYDEV}]prism0)\n"
  474. else
  475. printf "\n\t\t(failed to enable experimental wl monitor mode for [${PHYDEV}${1})\n"
  476. fi
  477. else
  478. printf "\n\tUnable to write to /proc/brcm_monitor0, cannot enable monitor mode.\n"
  479. fi
  480. else
  481. printf "\n\tThis version of wl does not appear to support monitor mode.\n"
  482. fi
  483. }
  484. #startDarwinIface() {
  485. # if [ -x /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport ]; then
  486. # if [ -n "${CH}" ] && [ ${CH} -lt 220 ]; then
  487. # /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport $1 sniff ${CH}
  488. # else
  489. # printf "Channel is set to none channel value of ${CH}
  490. # fi
  491. # fi
  492. #}
  493. setChannelMac80211() {
  494. setLink ${1} up
  495. if [ -n "${CH}" ]; then
  496. if [ ${CH} -lt 1000 ]; then
  497. if [ -r "/sys/class/net/$1/phy80211/name" ]; then
  498. channel_list="$(iw phy $(cat /sys/class/net/$1/phy80211/name) info 2>&1 | awk -F'[][]' '$2{print $2}')"
  499. local hardware_valid_channel=1
  500. for i in $channel_list; do
  501. if [ "${CH}" = "${i}" ]; then
  502. hardware_valid_channel=0
  503. break
  504. fi
  505. done
  506. if [ "${hardware_valid_channel}" = "1" ]; then
  507. printf "Channel ${CH} does not appear to be supported by ${1} hardware, defaulting to channel 3.\n\n"
  508. CH=3
  509. fi
  510. fi
  511. IW_ERROR="$(iw dev ${1} set channel ${CH} 2>&1)"
  512. else
  513. if [ -r "/sys/class/net/$1/phy80211/name" ]; then
  514. frequency_list="$(iw phy $(cat /sys/class/net/$1/phy80211/name) info 2>&1 | sed -nr 's/.*( |^)([0-9]+) MHz .*/\2/p')"
  515. local hardware_valid_freq=1
  516. for i in $frequency_list; do
  517. if [ "${CH}" = "${i}" ]; then
  518. hardware_valid_freq=0
  519. break
  520. fi
  521. print
  522. done
  523. if [ "${hardware_valid_freq}" = "1" ]; then
  524. printf "Frequency ${CH} does not appear to be supported by ${1} hardware, defaulting to 2422 Mhz.\n\n"
  525. CH="2422"
  526. fi
  527. fi
  528. IW_ERROR="$(iw dev ${1} set freq "${CH}" 2>&1)"
  529. fi
  530. else
  531. printf "CH is unset, this should not be possible.\n"
  532. exit 1
  533. fi
  534. if [ -n "${IW_ERROR}" ]; then
  535. printf "\nError setting channel: ${IW_ERROR}\n"
  536. if printf "${IW_ERROR}" | grep -q "(-16)"; then
  537. printf "Error -16 likely means your card was set back to station mode by something.\n"
  538. printf "Removing non-monitor ${1} interface...\n"
  539. stopMac80211Iface "${1}" abort
  540. exit 1
  541. fi
  542. if printf "${IW_ERROR}" | grep -q "(-22)"; then
  543. printf "Unable to set channel/frequency ${CH}, most likely it is outside of regulatory domain\n\n"
  544. fi
  545. fi
  546. }
  547. stopDeprecatedIface() {
  548. setLink $1 down
  549. iwconfig $1 mode Managed > /dev/null 2>&1
  550. setLink $1 up
  551. printf " (monitor mode disabled)"
  552. }
  553. stopMac80211Iface() {
  554. if [ -f /sys/class/net/${1}/type ]; then
  555. if [ "${2}" != "abort" ] && [ "$(cat /sys/class/net/${1}/type)" != "803" ]; then
  556. printf "\n\nYou are trying to stop a device that isn't in monitor mode.\n"
  557. printf "Doing so is a terrible idea, if you really want to do it then you\n"
  558. printf "need to type 'iw ${1} del' yourself since it is a terrible idea.\n"
  559. printf "Most likely you want to remove an interface called wlan[0-9]mon\n"
  560. printf "If you feel you have reached this warning in error,\n"
  561. printf "please report it.\n"
  562. exit 1
  563. else
  564. if [ "${DRIVER}" = "8812au" ] || [ "${DRIVER}" = "8814au" ] || [ "${DRIVER}" = "88XXau" ]; then
  565. #grumble grumble, seriously crap vendor driver
  566. stopDeprecatedIface ${1}
  567. return
  568. fi
  569. if [ "${ELITE}" = "0" ]; then
  570. local need_sta=1
  571. if [ -d /sys/class/ieee80211/${PHYDEV}/device/net ]; then
  572. for i in $(ls /sys/class/ieee80211/${PHYDEV}/device/net/); do
  573. if [ -r /sys/class/ieee80211/${PHYDEV}/device/net/${i}/type ] && [ "$(cat /sys/class/ieee80211/${PHYDEV}/device/net/${i}/type)" = "1" ]; then
  574. [ "${2}" != "abort" ] && printf "\n\t\t(mac80211 station mode vif already available for [${PHYDEV}]${1} on [${PHYDEV}]${i})\n"
  575. need_sta=0
  576. fi
  577. done
  578. fi
  579. if [ "${need_sta}" = "1" ] && [ -e /sys/class/net/${1%mon}/phy80211/name ]; then
  580. if [ "$(cat /sys/class/net/${1%mon}/phy80211/name)" = "${PHYDEV}" ]; then
  581. printf "\nYou already have a ${1%mon} device but it is NOT in station mode."
  582. printf "\nWhatever you did, don't do it again."
  583. printf "\nPlease run \"iw ${1%mon} del\" before attempting to continue\n"
  584. exit 1
  585. else
  586. printf "\nYou already have a ${1%mon} device, but it is not on the same phy as ${1}.\n"
  587. printf "\nAttemping to pick a new name...\n"
  588. findFreeInterface station
  589. fi
  590. fi
  591. if [ "${need_sta}" = "1" ]; then
  592. IW_ERROR="$(iw phy ${PHYDEV} interface add ${1%mon} type station 2>&1)"
  593. if [ -z "${IW_ERROR}" ]; then
  594. interface="${1%mon}"
  595. if [ -d /sys/class/ieee80211/${PHYDEV}/device/net ]; then
  596. for i in $(ls /sys/class/ieee80211/${PHYDEV}/device/net/); do
  597. if [ "$(cat /sys/class/ieee80211/${PHYDEV}/device/net/${i}/type)" = "1" ]; then
  598. #here is where we catch udev renaming our interface
  599. interface="${i}"
  600. fi
  601. done
  602. fi
  603. printf "\n\t\t(mac80211 station mode vif enabled on [${PHYDEV}]${interface})\n"
  604. else
  605. printf "\n\n ERROR adding station mode interface: ${IW_ERROR}\n"
  606. fi
  607. fi
  608. fi
  609. setLink ${1} down
  610. IW_ERROR="$(iw dev "${1}" del 2>&1 | grep "nl80211 not found")"
  611. if [ -z "$IW_ERROR" ]; then
  612. if [ "${2}" != "abort" ]; then
  613. printf "\n\t\t(mac80211 monitor mode vif disabled for [${PHYDEV}]${1})\n"
  614. elif [ "${2}" = "abort" ]; then
  615. printf "\nWARNING: unable to start monitor mode, please run \"airmon-ng check kill\"\n"
  616. fi
  617. else
  618. if [ -f /sys/class/ieee80211/${PHYDEV}/remove_iface ]; then
  619. printf "${1}" > /sys/class/ieee80211/${PHYDEV}/remove_iface
  620. printf "\n\t\t(mac80211 monitor mode vif disabled for [${PHYDEV}]${1})\n"
  621. else
  622. printf "\n\nERROR: Neither the sysfs interface links nor the iw command is available.\nPlease download and install iw from\n$IW_SOURCE\n"
  623. fi
  624. fi
  625. fi
  626. fi
  627. }
  628. stopwlIface() {
  629. if [ -f "/proc/brcm_monitor0" ]; then
  630. if [ -r "/proc/brcm_monitor0" ]; then
  631. local brcm_monitor="$(cat /proc/brcm_monitor0)"
  632. if [ "$brcm_monitor" = "0" ]; then
  633. printf "\n\t\t(experimental wl monitor mode vif already disabled for [${PHYDEV}]${1})\n"
  634. return 0
  635. fi
  636. fi
  637. if [ -w "/proc/brcm_monitor0" ]; then
  638. printf "0" > /proc/brcm_monitor0
  639. if [ "$?" = "0" ]; then
  640. printf "\n\t\t(experimental wl monitor mode vif disabled for [${PHYDEV}]${1})\n"
  641. else
  642. printf "\n\t\t(failed to disable experimental wl monitor mode for [${PHYDEV}${1})\n"
  643. fi
  644. else
  645. printf "\n\tUnable to write to /proc/brcm_monitor0, cannot disable monitor mode.\n"
  646. fi
  647. else
  648. printf "\n\tThis version of wl does not appear to support monitor mode.\n"
  649. fi
  650. }
  651. getDriver() {
  652. unset DRIVER
  653. #standard detection path, this is all that is needed for proper drivers
  654. #DRIVER=$(printf "$ethtool_output" | awk '/driver/ {print $2}')
  655. #if $(modinfo -F filename ${DRIVER} > /dev/null 2>&1)
  656. #then
  657. # true
  658. #else
  659. # unset DRIVER
  660. #fi
  661. #if [ "$DRIVER" = "" ]
  662. #then
  663. if [ -f /sys/class/net/$1/device/uevent ]; then
  664. DRIVER="$(awk -F'=' '$1 == "DRIVER" {print $2}' /sys/class/net/$1/device/uevent)"
  665. fi
  666. #fi
  667. #here we test for driver usb, ath9k_htc,rt2870, possibly others show this
  668. if [ "$DRIVER" = "usb" ]; then
  669. printf "Warn ON: USB\n"
  670. BUSADDR="$(printf "$ethtool_output" | awk '/bus-info/ {print $2}'):1.0"
  671. if [ "$DEBUG" = "1" ]; then
  672. printf "${BUSADDR}\n"
  673. fi
  674. if [ -n "$BUSADDR" ]; then
  675. if [ -f /sys/class/net/$1/device/"$BUSADDR"/uevent ]; then
  676. DRIVER="$(awk -F'=' '$1 == "DRIVER" {print $2}' /sys/class/net/$1/device/$BUSADDR/uevent)"
  677. fi
  678. fi
  679. #here we can normalize driver names we don't like
  680. if [ "$DRIVER" = "rt2870" ]; then
  681. DRIVER="rt2870sta"
  682. fi
  683. if [ -f /sys/class/net/$1/device/idProduct ]; then
  684. if [ "$(cat /sys/class/net/$1/device/idProduct)" = "3070" ]; then
  685. DRIVER="rt3070sta"
  686. fi
  687. fi
  688. fi
  689. if [ "$DRIVER" = "rtl8187L" ]; then
  690. DRIVER="r8187l"
  691. fi
  692. if [ "$DRIVER" = "rtl8187" ] && [ "$STACK" = "ieee80211" ]; then
  693. DRIVER="r8187"
  694. fi
  695. if [ "$DRIVER" = "rtl88xxau" ]; then
  696. DRIVER="88XXau"
  697. fi
  698. if [ "$DRIVER" = "rtl8812au" ]; then
  699. DRIVER="8812au"
  700. fi
  701. #Here we will catch the broken lying drivers not caught above
  702. #currently this only functions for pci devices and not usb since lsusb has no -k option
  703. if [ "${MODINFO}" = "1" ]; then
  704. if $(modinfo -F filename $DRIVER > /dev/null 2>&1)
  705. then
  706. true
  707. else
  708. save="$DRIVER"
  709. if [ -n "${DEVICEID}" ] && [ "$BUS" = "pci" ]; then
  710. DRIVER="$(lspci -d $DEVICEID -k | awk '/modules/ {print $3}')"
  711. fi
  712. if [ -z "${BUS}" ] || [ "${BUS}" != 'sdio' ]; then
  713. unset DRIVER
  714. fi
  715. if [ -n "$save" ] && [ -z "$DRIVER" ] ; then
  716. DRIVER="$save"
  717. fi
  718. fi
  719. fi
  720. if [ -z "$DRIVER" ] ; then
  721. DRIVER="??????"
  722. fi
  723. if [ "$DEBUG" = "1" ]; then
  724. printf "getdriver() $DRIVER\n"
  725. fi
  726. }
  727. getFrom() {
  728. #from detection
  729. FROM="K"
  730. if [ "${MODINFO}" = "1" ] && [ -f /proc/modules ]; then
  731. if modinfo -F filename $DRIVER 2>&1 | grep -q 'kernel/drivers'
  732. then
  733. FROM="K"
  734. #we add special handling here because we hate the vendor drivers AND they install in the wrong place
  735. if [ "$DRIVER" = "r8187" ]; then
  736. FROM="V"
  737. elif [ "$DRIVER" = "r8187l" ]; then
  738. FROM="V"
  739. elif [ "$DRIVER" = "rt5390sta" ]; then
  740. FROM="V"
  741. elif [ "${DRIVER}" = "8812au" ] || [ "${DRIVER}" = "8814au" ]; then
  742. FROM="V"
  743. fi
  744. elif modinfo -F filename $DRIVER 2>&1 | grep -q 'updates/drivers'
  745. then
  746. FROM="C"
  747. elif modinfo -F filename $DRIVER 2>&1 | grep -q misc
  748. then
  749. FROM="V"
  750. elif modinfo -F filename $DRIVER 2>&1 | grep -q staging
  751. then
  752. FROM="S"
  753. else
  754. FROM="?"
  755. fi
  756. else
  757. FROM="K"
  758. fi
  759. #maybe add an 'intree' check?
  760. if [ "$DEBUG" = "1" ]; then
  761. printf "getFrom() $FROM\n"
  762. fi
  763. }
  764. getFirmware() {
  765. FIRMWARE="$(printf "$ethtool_output" | awk '/firmware-version/ {print $2}')"
  766. #ath9k_htc firmware is a shorter version number than most so trap and make it pretty
  767. if [ "$DRIVER" = "ath9k_htc" ]; then
  768. FIRMWARE="$FIRMWARE\t"
  769. fi
  770. if [ "$FIRMWARE" = "N/A" ]; then
  771. FIRMWARE="$FIRMWARE\t"
  772. elif [ -z "$FIRMWARE" ]; then
  773. FIRMWARE="unavailable"
  774. fi
  775. if [ "$DEBUG" = "1" ]; then
  776. printf "getFirmware $FIRMWARE\n"
  777. fi
  778. }
  779. getChipset() {
  780. #this needs cleanup, we shouldn't have multiple lines assigning chipset per bus
  781. #fix this to be one line per bus
  782. if [ -f /sys/class/net/$1/device/modalias ]; then
  783. if [ "$BUS" = "usb" ]; then
  784. if [ "${LSUSB}" = "1" ]; then
  785. BUSINFO="$(cut -d ":" -f 2 /sys/class/net/$1/device/modalias | cut -b 1-10 | sed 's/^.//;s/p/:/')"
  786. CHIPSET="$(lsusb -d "$BUSINFO" | head -n1 - | cut -f3- -d ":" | sed 's/^....//;s/ Network Connection//g;s/ Wireless Adapter//g;s/^ //')"
  787. elif [ "${LSUSB}" = "0" ]; then
  788. printf "Your system doesn't seem to support usb but we found usb hardware, please report this.\n"
  789. exit 1
  790. fi
  791. #yes the below line looks insane, but broadcom appears to define all the internal buses so we have to detect them here
  792. elif [ "${BUS}" = "pci" -o "${BUS}" = "pcmcia" ] && [ "${LSPCI}" = "1" ]; then
  793. if [ -f /sys/class/net/$1/device/vendor ] && [ -f /sys/class/net/$1/device/device ]; then
  794. DEVICEID="$(cat /sys/class/net/$1/device/vendor):$(cat /sys/class/net/$1/device/device)"
  795. CHIPSET="$(lspci -d $DEVICEID | cut -f3- -d ":" | sed 's/Wireless LAN Controller //g;s/ Network Connection//g;s/ Wireless Adapter//;s/^ //')"
  796. else
  797. BUSINFO="$(printf "$ethtool_output" | grep bus-info | cut -d ":" -f "3-" | sed 's/^ //')"
  798. CHIPSET="$(lspci | grep "$BUSINFO" | head -n1 - | cut -f3- -d ":" | sed 's/Wireless LAN Controller //g;s/ Network Connection//g;s/ Wireless Adapter//;s/^ //')"
  799. DEVICEID="$(lspci -nn | grep "$BUSINFO" | grep '[[0-9][0-9][0-9][0-9]:[0-9][0-9][0-9][0-9]' -o)"
  800. fi
  801. elif [ "${BUS}" = "sdio" ]; then
  802. if [ -f /sys/class/net/$1/device/vendor ] && [ -f /sys/class/net/$1/device/device ]; then
  803. DEVICEID="$(cat /sys/class/net/$1/device/vendor):$(cat /sys/class/net/$1/device/device)"
  804. fi
  805. if [ "${DEVICEID}" = '0x02d0:0x4330' ]; then
  806. CHIPSET='Broadcom 4330'
  807. elif [ "${DEVICEID}" = '0x02d0:0x4329' ]; then
  808. CHIPSET='Broadcom 4329'
  809. elif [ "${DEVICEID}" = '0x02d0:0x4334' ]; then
  810. CHIPSET='Broadcom 4334'
  811. elif [ "${DEVICEID}" = '0x02d0:0xa94c' ]; then
  812. CHIPSET='Broadcom 43340'
  813. elif [ "${DEVICEID}" = '0x02d0:0xa94d' ]; then
  814. CHIPSET='Broadcom 43341'
  815. elif [ "${DEVICEID}" = '0x02d0:0x4324' ]; then
  816. CHIPSET='Broadcom 43241'
  817. elif [ "${DEVICEID}" = '0x02d0:0x4335' ]; then
  818. CHIPSET='Broadcom 4335/4339'
  819. elif [ "${DEVICEID}" = '0x02d0:0xa962' ]; then
  820. CHIPSET='Broadcom 43362'
  821. elif [ "${DEVICEID}" = '0x02d0:0xa9a6' ]; then
  822. CHIPSET='Broadcom 43430'
  823. elif [ "${DEVICEID}" = '0x02d0:0x4345' ]; then
  824. CHIPSET='Broadcom 43455'
  825. elif [ "${DEVICEID}" = '0x02d0:0x4354' ]; then
  826. CHIPSET='Broadcom 4354'
  827. elif [ "${DEVICEID}" = '0x02d0:0xa887' ]; then
  828. CHIPSET='Broadcom 43143'
  829. else
  830. CHIPSET="unable to detect for sdio $DEVICEID"
  831. fi
  832. else
  833. CHIPSET="Not pci, usb, or sdio"
  834. fi
  835. #we don't do a check for usb here but it is obviously only going to work for usb
  836. elif [ -f /sys/class/net/$1/device/idVendor ] && [ -f /sys/class/net/$1/device/idProduct ]; then
  837. DEVICEID="$(cat /sys/class/net/$1/device/idVendor):$(cat /sys/class/net/$1/device/idProduct)"
  838. if [ "${LSUSB}" = "1" ]; then
  839. CHIPSET="$(lsusb | grep -i "$DEVICEID" | head -n1 - | cut -f3- -d ":" | sed 's/^....//;s/ Network Connection//g;s/ Wireless Adapter//g;s/^ //')"
  840. elif [ "${LSUSB}" = "0" ]; then
  841. CHIPSET="idVendor and idProduct found on non-usb device, please report this."
  842. fi
  843. elif [ "${DRIVER}" = "mac80211_hwsim" ]; then
  844. CHIPSET="Software simulator of 802.11 radio(s) for mac80211"
  845. elif $(printf "$ethtool_output" | awk '/bus-info/ {print $2}' | grep -q bcma)
  846. then
  847. BUS="bcma"
  848. if [ "${DRIVER}" = "brcmsmac" ] || [ "${DRIVER}" = "brcmfmac" ] || [ "${DRIVER}" = "b43" ]; then
  849. CHIPSET="Broadcom on bcma bus, information limited"
  850. else
  851. CHIPSET="Unrecognized driver \"${DRIVER}\" on bcma bus"
  852. fi
  853. else
  854. CHIPSET="non-mac80211 device? (report this!)"
  855. fi
  856. if [ "$DEBUG" = "1" ]; then
  857. printf "getchipset() $CHIPSET\n"
  858. printf "BUS = $BUS\n"
  859. printf "BUSINFO = $BUSINFO\n"
  860. printf "DEVICEID = $DEVICEID\n"
  861. fi
  862. }
  863. getBus() {
  864. if [ -f /sys/class/net/$1/device/modalias ]; then
  865. BUS="$(cut -d ":" -f 1 /sys/class/net/$1/device/modalias)"
  866. fi
  867. if [ "$DEBUG" = "1" ]; then
  868. printf "getBus $BUS\n"
  869. fi
  870. }
  871. getStack() {
  872. if [ -z "$1" ]; then
  873. return
  874. fi
  875. if [ -d /sys/class/net/$1/phy80211/ ]; then
  876. MAC80211="1"
  877. STACK="mac80211"
  878. else
  879. MAC80211="0"
  880. STACK="ieee80211"
  881. fi
  882. if [ -e /proc/sys/dev/$1/fftxqmin ]; then
  883. MAC80211="0"
  884. STACK="net80211"
  885. fi
  886. if [ "$DEBUG" = "1" ]; then
  887. printf "getStack $STACK\n"
  888. fi
  889. }
  890. getExtendedInfo() {
  891. #stuff rfkill info into extended if nothing else is there
  892. rfkill_check ${PHYDEV}
  893. rfkill_retcode="$?"
  894. if [ "${rfkill_retcode}" = "1" ]; then
  895. EXTENDED="rfkill soft blocked"
  896. elif [ "${rfkill_retcode}" = "2" ]; then
  897. EXTENDED="rfkill hard blocked"
  898. elif [ "${rfkill_redcode}" = "3" ]; then
  899. EXTENDED="rfkill hard and soft blocked"
  900. fi
  901. if [ "$DRIVER" = "??????" ]; then
  902. EXTENDED="\t Failure detecting driver properly please report"
  903. fi
  904. #first we set all the real (useful) info we can find
  905. if [ -f /sys/class/net/$1/device/product ]; then
  906. EXTENDED="\t$(cat /sys/class/net/$1/device/product)"
  907. fi
  908. #then we sweep for known broken drivers with no available better drivers
  909. if [ "$DRIVER" = "wl" ]; then
  910. if [ -f "/proc/brcm_monitor0" ]; then
  911. EXTENDED="Experimental monitor mode support"
  912. else
  913. EXTENDED="No known monitor support, try a newer version or b43"
  914. fi
  915. fi
  916. if [ "$DRIVER" = "brcmsmac" ]; then
  917. EXTENDED="Driver commonly referred to as brcm80211 (no injection yet)"
  918. fi
  919. if [ "$DRIVER" = "r8712u" ]; then
  920. EXTENDED="\t\t\t\tNo monitor or injection support"
  921. fi
  922. #lastly we detect all the broken drivers which have working alternatives
  923. KV="$(uname -r | awk -F'-' '{print $1}')"
  924. KVMAJOR="$(printf ${KV} | awk -F'.' '{print $1$2}')"
  925. KVMINOR="$(printf ${KV} | awk -F'.' '{print $3}')"
  926. if [ $KVMAJOR -lt 26 ]; then
  927. printf "You are running a kernel older than 2.6, I'm surprised it didn't error before now."
  928. if [ "$DEBUG" = "1" ]; then
  929. printf "${KVMAJOR} ${KVMINOR}\n"
  930. fi
  931. exit 1
  932. fi
  933. if [ "$DRIVER" = "rt2870sta" ]; then
  934. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "35" ]; then
  935. EXTENDED="\tBlacklist rt2870sta and use rt2800usb"
  936. else
  937. EXTENDED="\tUpgrade to kernel 2.6.35 or install compat-wireless stable"
  938. fi
  939. #add in a flag for "did you tell use to do X" and emit instructions
  940. elif [ "$DRIVER" = "rt3070sta" ]; then
  941. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "35" ]; then
  942. EXTENDED="\tBlacklist rt3070sta and use rt2800usb"
  943. else
  944. EXTENDED="\tUpgrade to kernel 2.6.35 or install compat-wireless stable"
  945. fi
  946. elif [ "$DRIVER" = "rt5390sta" ]; then
  947. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "39" ]; then
  948. EXTENDED="\tBlacklist rt5390sta and use rt2800usb"
  949. else
  950. EXTENDED="\tUpgrade to kernel 2.6.39 or install compat-wireless stable"
  951. fi
  952. elif [ "$DRIVER" = "ar9170usb" ]; then
  953. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "37" ]; then
  954. EXTENDED="\tBlacklist ar9170usb and use carl9170"
  955. else
  956. EXTENDED="\tUpgrade to kernel 2.6.37 or install compat-wireless stable"
  957. fi
  958. elif [ "$DRIVER" = "arusb_lnx" ]; then
  959. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "37" ]; then
  960. EXTENDED="\tBlacklist arusb_lnx and use carl9170"
  961. else
  962. EXTENDED="\tUpgrade to kernel 2.6.37 or install compat-wireless stable"
  963. fi
  964. elif [ "$DRIVER" = "r8187" ]; then
  965. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "29" ]; then
  966. EXTENDED="\t\tBlacklist r8187 and use rtl8187 from the kernel"
  967. else
  968. EXTENDED="\t\tUpgrade to kernel 2.6.29 or install compat-wireless stable"
  969. fi
  970. elif [ "$DRIVER" = "r8187l" ]; then
  971. if [ "$KVMAJOR" = "26" ] && [ "$KVMINOR" -ge "29" ]; then
  972. EXTENDED="\t\tBlacklist r8187l and use rtl8187 from the kernel"
  973. else
  974. EXTENDED="\t\tUpgrade to kernel 2.6.29 or install compat-wireless stable"
  975. fi
  976. fi
  977. #okay, now I take overload to a new level
  978. #if there is nothing else here to complain about, show mode
  979. if [ -z "${EXTENDED}" ]; then
  980. if [ -r "/sys/class/net/${1}/type" ]; then
  981. NET_TYPE="$(cat /sys/class/net/${1}/type)"
  982. elif [ -r "/sys/class/ieee80211/${PHYDEV}/device/net/${1}/type" ]; then
  983. NET_TYPE="$(cat /sys/class/ieee80211/${PHYDEV}/device/net/${1}/type)"
  984. fi
  985. if [ -n "${NET_TYPE}" ]; then
  986. if [ "${NET_TYPE}" = "803" ]; then
  987. EXTENDED="mode monitor"
  988. elif [ "${NET_TYPE}" = "1" ]; then
  989. EXTENDED="mode managed"
  990. else
  991. EXTENDED="mode ${NET_TYPE} unknown"
  992. fi
  993. fi
  994. fi
  995. }
  996. scanProcesses() {
  997. #this test means it errored and said it was busybox since busybox doesn't print without error
  998. if (ps -A 2>&1 | grep -q BusyBox)
  999. then
  1000. #busybox in openwrt cannot handle -A but its output by default is -A
  1001. psopts=""
  1002. else
  1003. psopts="-A"
  1004. fi
  1005. if ( ps -o comm= 2>&1 | grep -q BusyBox )
  1006. then
  1007. #busybox in openwrt cannot handle -o
  1008. pso="0"
  1009. else
  1010. pso="1"
  1011. fi
  1012. PROCESSES="wpa_action\|wpa_supplicant\|wpa_cli\|dhclient\|ifplugd\|dhcdbd\|dhcpcd\|udhcpc\|NetworkManager\|knetworkmanager\|avahi-autoipd\|avahi-daemon\|wlassistant\|wifibox"
  1013. #PS_ERROR="invalid\|illegal"
  1014. if [ -x "$(command -v service 2>&1)" ] && [ "$1" = "kill" ]; then
  1015. service network-manager stop 2> /dev/null > /dev/null
  1016. service NetworkManager stop 2> /dev/null > /dev/null
  1017. service avahi-daemon stop 2> /dev/null > /dev/null
  1018. fi
  1019. unset match
  1020. if [ "${pso}" = 1 ]; then
  1021. match="$(ps ${psopts} -o comm= | grep ${PROCESSES} | grep -v grep | wc -l)"
  1022. elif [ "${pso}" = 0 ]; then
  1023. #openwrt busybox grep hits on itself so we -v it out
  1024. match="$(ps ${psopts} | grep ${PROCESSES} | grep -v grep | wc -l)"
  1025. fi
  1026. if [ ${match} -gt 0 ] && [ "${1}" != "kill" ]; then
  1027. printf "Found $match processes that could cause trouble.\n"
  1028. printf "Kill them using 'airmon-ng check kill' before putting\n"
  1029. printf "the card in monitor mode, they will interfere by changing channels\n"
  1030. printf "and sometimes putting the interface back in managed mode\n\n"
  1031. else
  1032. if [ "${1}" != "kill" ] && [ -n "${1}" ]; then
  1033. printf "No interfering processes found\n"
  1034. return
  1035. fi
  1036. fi
  1037. if [ ${match} -gt 0 ]; then
  1038. if [ "${1}" = "kill" ]; then
  1039. printf "Killing these processes:\n\n"
  1040. fi
  1041. if [ "${pso}" = "1" ]; then
  1042. ps ${psopts} -o pid=PID -o comm=Name | grep "${PROCESSES}\|PID"
  1043. else
  1044. #openwrt busybox grep hits on itself so we -v it out
  1045. ps ${psopts} | grep "${PROCESSES}\|PID | grep -v grep"
  1046. fi
  1047. if [ "${1}" = "kill" ]; then
  1048. #we have to use signal 9 because things like nm actually respawn wpa_supplicant too quickly
  1049. if [ "${pso}" = "1" ]; then
  1050. for pid in $(ps ${psopts} -o pid= -o comm= | grep ${PROCESSES} | awk '{print $1}'); do
  1051. kill -9 ${pid}
  1052. done
  1053. else
  1054. #openwrt busybox grep hits on itself so we -v it out
  1055. for pid in $(ps ${psopts} | grep ${PROCESSES} | grep -v grep | awk '{print $1}'); do
  1056. kill -9 ${pid}
  1057. done
  1058. fi
  1059. fi
  1060. fi
  1061. #i=1
  1062. #while [ $i -le $match ]
  1063. #do
  1064. # pid=$(ps ${psopts} -o pid= -o comm= | grep $PROCESSES | head -n $i | tail -n 1 | awk '{print $1}')
  1065. # pname=$(ps ${psopts} -o pid= -o comm= | grep $PROCESSES | head -n $i | tail -n 1 | awk '{print $2}')
  1066. # if [ x"$1" != "xkill" ]
  1067. # then
  1068. # printf "${pid}\t${pname}\n"
  1069. # else
  1070. # kill ${pid}
  1071. # fi
  1072. # i=$(($i+1))
  1073. #done
  1074. printf "\n"
  1075. #this stub is for checking against the interface name, but since it almost never hits why bother?
  1076. #if [ x"${1}" != "x" -a x"${1}" != "xkill" ]
  1077. #then
  1078. # #the next line doesn't work on busybox ps because -p is unimplimented
  1079. # match2=$(ps -o comm= -p 1 2>&1 | grep $PS_ERROR -c)
  1080. # if [ ${match2} -gt 0 ]
  1081. # then
  1082. # return
  1083. # fi
  1084. #
  1085. # for i in $(ps auxw | grep ${1} | grep -v "grep" | grep -v "airmon-ng" | awk '{print $2}')
  1086. # do
  1087. # pname=$(ps -o comm= -p ${i})
  1088. # printf "Process with PID ${i} ($pname) is running on interface ${1}\n"
  1089. # done
  1090. #fi
  1091. }
  1092. listInterfaces() {
  1093. unset iface_list
  1094. for iface in $(ls -1 /sys/class/net)
  1095. do
  1096. if [ -f /sys/class/net/${iface}/uevent ]; then
  1097. if $(grep -q DEVTYPE=wlan /sys/class/net/${iface}/uevent)
  1098. then
  1099. iface_list="${iface_list}\n ${iface}"
  1100. fi
  1101. fi
  1102. done
  1103. # this block only adds garbage to me
  1104. #if [ -x "$(command -v iwconfig 2>&1)" ] && [ -x "$(command -v sort 2>&1)" ]; then
  1105. # for iface in $(iwconfig 2> /dev/null | sed 's/^\([a-zA-Z0-9_.]*\) .*/\1/'); do
  1106. # iface_list="${iface_list}\n ${iface}"
  1107. # done
  1108. # iface_list="$(printf "${iface_list}" | sort -bu)"
  1109. #fi
  1110. }
  1111. getPhy() {
  1112. if [ -z "$1" ]; then
  1113. return
  1114. fi
  1115. if [ $MAC80211 = "0" ]; then
  1116. PHYDEV="null"
  1117. return
  1118. fi
  1119. if [ -r /sys/class/net/$1/phy80211/name ]; then
  1120. PHYDEV="$(cat /sys/class/net/$1/phy80211/name)"
  1121. fi
  1122. if [ -d /sys/class/net/$1/phy80211/ ] && [ -z "${PHYDEV}" ]; then
  1123. PHYDEV="$(ls -l "/sys/class/net/$1/phy80211" | sed 's/^.*\/\([a-zA-Z0-9_-]*\)$/\1/')"
  1124. fi
  1125. }
  1126. checkvm() {
  1127. #this entire section of code is completely stolen from Carlos Perez's work in checkvm.rb for metasploit and rewritten (poorly) in sh
  1128. #check loaded modules
  1129. if [ -x "$(command -v lsmod 2>&1)" ]; then
  1130. lsmod_data="$(lsmod 2>&1 | awk '{print $1}')"
  1131. if [ -n "${lsmod}" ]; then
  1132. printf "${lsmod_data}" | grep -iqE "vboxsf|vboxguest" 2> /dev/null && vm="VirtualBox"
  1133. printf "${lsmod_data}" | grep -iqE "vmw_ballon|vmxnet|vmw" 2> /dev/null && vm="VMware"
  1134. printf "${lsmod_data}" | grep -iqE "xen-vbd|xen-vnif" 2> /dev/null && vm="Xen"
  1135. printf "${lsmod_data}" | grep -iqE "virtio_pci|virtio_net" 2> /dev/null && vm="Qemu/KVM"
  1136. printf "${lsmod_data}" | grep -iqE "hv_vmbus|hv_blkvsc|hv_netvsc|hv_utils|hv_storvsc" && vm="MS Hyper-V"
  1137. [ -n "${vm}" ] && vm_from="lsmod"
  1138. fi
  1139. fi
  1140. #check scsi driver
  1141. if [ -z "${vm_from}" ]; then
  1142. if [ -r /proc/scsi/scsi ]; then
  1143. grep -iq "vmware" /proc/scsi/scsi 2> /dev/null && vm="VMware"
  1144. grep -iq "vbox" /proc/scsi/scsi 2> /dev/null && vm="VirtualBox"
  1145. [ -n "${vm}" ] && vm_from="/pro/scsi/scsi"
  1146. fi
  1147. fi
  1148. # Check IDE Devices
  1149. if [ -z "${vm_from}" ]; then
  1150. if [ -d /proc/ide ]; then
  1151. ide_model="$(cat /proc/ide/hd*/model)"
  1152. printf "${ide_model}" | grep -iq "vbox" 2> /dev/null && vm="VirtualBox"
  1153. printf "${ide_model}" | grep -iq "vmware" 2> /dev/null && vm="VMware"
  1154. printf "${ide_model}" | grep -iq "qemu" 2> /dev/null && vm="Qemu/KVM"
  1155. printf "${ide_model}" | grep -iqE "virtual (hd|cd)" 2> /dev/null && vm="Hyper-V/Virtual PC"
  1156. [ -n "${vm}" ] && vm_from="ide_model"
  1157. fi
  1158. fi
  1159. # Check using lspci
  1160. if [ -z "${vm_from}" ] && [ "${LSPCI}" = "1" ]; then
  1161. lspci_data="$(lspci 2>&1)"
  1162. printf "${lspci_data}" | grep -iq "vmware" 2> /dev/null && vm="VMware"
  1163. printf "${lspci_data}" | grep -iq "virtualbox" 2> /dev/null && vm="VirtualBox"
  1164. [ -n "${vm}" ] && vm_from="lspci"
  1165. fi
  1166. # Xen bus check
  1167. ## XXX: Removing unsafe check
  1168. # this check triggers if CONFIG_XEN_PRIVILEGED_GUEST=y et al are set in kconfig (debian default) even in not actually a guest
  1169. #if [ -z ${vm} ]
  1170. #then
  1171. # ls -1 /sys/bus | grep -iq "xen" 2> /dev/null && vm="Xen"
  1172. # vm_from="/sys/bus/xen"
  1173. #fi
  1174. # Check using lscpu
  1175. if [ -z "${vm_from}" ]; then
  1176. if [ -x "$(command -v lscpu 2>&1)" ]; then
  1177. lscpu_data="$(lscpu 2>&1)"
  1178. printf "${lscpu_data}" | grep -iq "Xen" 2> /dev/null && vm="Xen"
  1179. printf "${lscpu_data}" | grep -iq "KVM" 2> /dev/null && vm="KVM"
  1180. printf "${lscpu_data}" | grep -iq "Microsoft" 2> /dev/null && vm="MS Hyper-V"
  1181. [ -n "${vm}" ] && vm_from="lscpu"
  1182. fi
  1183. fi
  1184. #Check vmnet
  1185. if [ -z "${vm_from}" ]; then
  1186. if [ -e /dev/vmnet ]; then
  1187. vm="VMware"
  1188. vm_from="/dev/vmnet"
  1189. fi
  1190. fi
  1191. #Check dmi info
  1192. if [ -z "${vm_from}" ]; then
  1193. if [ -x "$(command -v dmidecode 2>&1)" ]; then
  1194. dmidecode 2>&1 | grep -iq "microsoft corporation" 2> /dev/null && vm="MS Hyper-V"
  1195. dmidecode 2>&1 | grep -iq "vmware" 2> /dev/null && vm="VMware"
  1196. dmidecode 2>&1 | grep -iq "virtualbox" 2> /dev/null && vm="VirtualBox"
  1197. dmidecode 2>&1 | grep -iq "qemu" 2> /dev/null && vm="Qemu/KVM"
  1198. dmidecode 2>&1 | grep -iq "domu" 2> /dev/null && vm="Xen"
  1199. [ -n "${vm}" ] && vm_from="dmi_info"
  1200. fi
  1201. fi
  1202. # Check dmesg Output
  1203. if [ -z "${vm_from}" ]; then
  1204. if [ -x "$(command -v dmesg 2>&1)" ]; then
  1205. dmesg | grep -iqE "vboxbios|vboxcput|vboxfacp|vboxxsdt|(vbox cd-rom)|(vbox harddisk)" && vm="VirtualBox"
  1206. dmesg | grep -iqE "(vmware virtual ide)|(vmware pvscsi)|(vmware virtual platform)" && vm="VMware"
  1207. dmesg | grep -iqE "(xen_mem)|(xen-vbd)" && vm="Xen"
  1208. dmesg | grep -iqE "(qemu virtual cpu version)" && vm="Qemu/KVM"
  1209. [ -n "${vm}" ] && vm_from="dmesg"
  1210. fi
  1211. fi
  1212. checkvm_status="run"
  1213. }
  1214. #end function definitions
  1215. #begin execution
  1216. #here we check for any phys that have no interfaces to pick up The Lost Phys
  1217. handleLostPhys
  1218. listInterfaces
  1219. if [ "${1}" = "check" ] || [ "${1}" = "start" ]; then
  1220. if [ "${2}" = "kill" ]; then
  1221. #if we are killing, tell scanProcesses that
  1222. scanProcesses "${2}"
  1223. exit
  1224. elif [ "${1}" = "start" ]; then
  1225. #this stub can send scanProcesses the interface name
  1226. #but this seems entirely unreliable so just run generic
  1227. #scanProcesses "${2}"
  1228. scanProcesses
  1229. else
  1230. scanProcesses
  1231. exit
  1232. fi
  1233. fi
  1234. if [ "$#" != "0" ]; then
  1235. if [ "$1" != "start" ] && [ "$1" != "stop" ]; then
  1236. usage
  1237. fi
  1238. if [ -z "$2" ]; then
  1239. usage
  1240. fi
  1241. fi
  1242. #startup checks complete, headers then main
  1243. if [ "$DEBUG" = "1" ]; then
  1244. if [ -x "$(command -v readlink 2>&1)" ]; then
  1245. printf "/bin/sh -> $(readlink -f /bin/sh)\n"
  1246. if $(readlink -f /bin/sh) --version > /dev/null 2>&1
  1247. then
  1248. printf "$($(readlink -f /bin/sh) --version)\n"
  1249. fi
  1250. else
  1251. ls -l /bin/sh
  1252. if /bin/sh --version > /dev/null 2>&1
  1253. then
  1254. /bin/sh --version
  1255. fi
  1256. fi
  1257. if [ -n "$SHELL" ]; then
  1258. if $SHELL --version > /dev/null 2>&1
  1259. then
  1260. printf "\nSHELL is $($SHELL --version)\n\n"
  1261. else
  1262. printf "\nSHELL is $SHELL\n\n"
  1263. fi
  1264. fi
  1265. fi
  1266. if [ "$VERBOSE" = "1" ]; then
  1267. if [ -n "$(command -v lsb_release 2> /dev/null)" ]; then
  1268. lsb_release -a
  1269. printf "\n"
  1270. fi
  1271. uname -a
  1272. checkvm
  1273. if [ -n "${vm}" ]; then
  1274. printf "Detected VM using ${vm_from}\n"
  1275. printf "This appears to be a ${vm} Virtual Machine\n"
  1276. printf "If your system supports VT-d, it may be possible to use PCI devices\n"
  1277. printf "If your system does not support VT-d, you can only use USB wifi cards\n"
  1278. fi
  1279. printf "\nK indicates driver is from $(uname -r)\n"
  1280. if [ "${MODPROBE}" = "1" ]; then
  1281. modprobe compat > /dev/null 2>&1
  1282. if [ -r /sys/module/compat/parameters/compat_version ]; then
  1283. printf "C indicates driver is from $(cat /sys/module/compat/parameters/compat_version)\n"
  1284. fi
  1285. fi
  1286. printf "V indicates driver comes directly from the vendor, almost certainly a bad thing\n"
  1287. printf "S indicates driver comes from the staging tree, these drivers are meant for reference not actual use, BEWARE\n"
  1288. printf "? indicates we do not know where the driver comes from... report this\n\n"
  1289. fi
  1290. if [ "${VERBOSE}" = "1" ]; then
  1291. printf "\nX[PHY]Interface\t\tDriver[Stack]-FirmwareRev\t\tChipset\t\t\t\t\t\t\t\t\t\tExtended Info\n\n"
  1292. else
  1293. printf "PHY\tInterface\tDriver\t\tChipset\n\n"
  1294. fi
  1295. #this whole block of code shouldn't be here, it makes no sense
  1296. #per shellcheck, this block is broken as it runs the loops once with iface=listIfaceUnspec instead of the output of listIFaceUnspec
  1297. #for iface in listIfaceUnspec; do
  1298. #
  1299. # if [ -e "/proc/sys/dev/$iface/fftxqmin" ]
  1300. # then
  1301. # setLink ${iface} up
  1302. # printf "$iface\t\tAtheros\t\tmadwifi-ng"
  1303. # if [ x$1 = "xstart" ] && [ x$2 = x$iface ]
  1304. # then
  1305. # IFACE=$(wlanconfig ath create wlandev $iface wlanmode monitor -bssid | grep ath)
  1306. # setLink ${iface} up
  1307. # if [ $CH -lt 1000 ]
  1308. # then
  1309. # iwconfig $IFACE channel $CH 2> /dev/null > /dev/null
  1310. # else
  1311. # iwconfig $IFACE freq "$CH"000000 2> /dev/null > /dev/null
  1312. # fi
  1313. # setLink ${IFACE} up
  1314. # UDEV_ISSUE=$?
  1315. # fi
  1316. #
  1317. # if [ x$1 = "xstop" ] && [ x$2 = x$iface ]
  1318. # then
  1319. # printf "$iface does not support 'stop', do it on ath interface\n"
  1320. # fi
  1321. #
  1322. # #why, dear god why is there a random newline here?
  1323. # printf "\n"
  1324. # sleep 1
  1325. # continue
  1326. # fi
  1327. #done
  1328. #end random block of code that needs to die
  1329. for iface in $(printf "${iface_list}"); do
  1330. unset ethtool_output DRIVER FROM FIRMWARE STACK MADWIFI MAC80211 BUS BUSADDR BUSINFO DEVICEID CHIPSET EXTENDED NET_TYPE PHYDEV ifacet DRIVERt FIELD1 FIELD1t FIELD2 FIELD2t CHIPSETt
  1331. #add a RUNNING check here and up the device if it isn't already
  1332. ethtool_output="$(ethtool -i $iface 2>&1)"
  1333. if [ "$ethtool_output" != "Cannot get driver information: Operation not supported" ]; then
  1334. getStack ${iface}
  1335. getBus ${iface}
  1336. getPhy ${iface}
  1337. getDriver ${iface}
  1338. getChipset ${iface}
  1339. if [ "${VERBOSE}" = "1" ]; then
  1340. getFrom ${iface}
  1341. getFirmware ${iface}
  1342. getExtendedInfo ${iface}
  1343. fi
  1344. else
  1345. printf "\nethtool failed...\n"
  1346. printf "Only mac80211 devices on kernel 2.6.33 or higher are officially supported by airmon-ng.\n"
  1347. exit 1
  1348. fi
  1349. #yes this really is the main output loop
  1350. if [ "${VERBOSE}" = "1" ]; then
  1351. #beautify output spacing (within reason)
  1352. FIELD1="${FROM}[${PHYDEV}]${iface}"
  1353. if [ ${#FIELD1} -gt 15 ]; then
  1354. FIELD1t="\t"
  1355. else
  1356. FIELD1t="\t\t"
  1357. fi
  1358. FIELD2="${DRIVER}[${STACK}]-${FIRMWARE}"
  1359. if [ ${#FIELD2} -gt 28 ]; then
  1360. FIELD2t="\t"
  1361. else
  1362. FIELD2t="\t\t"
  1363. fi
  1364. if [ -n "${EXTENDED}" ]; then
  1365. if [ ${#CHIPSET} -gt 70 ]; then
  1366. CHIPSETt="\t"
  1367. elif [ ${#CHIPSET} -gt 63 ]; then
  1368. CHIPSETt="\t\t"
  1369. elif [ ${#CHIPSET} -gt 56 ]; then
  1370. CHIPSETt="\t\t\t"
  1371. elif [ ${#CHIPSET} -gt 49 ]; then
  1372. CHIPSETt="\t\t\t\t"
  1373. elif [ ${#CHIPSET} -gt 39 ]; then
  1374. CHIPSETt="\t\t\t\t\t"
  1375. elif [ ${#CHIPSET} -gt 35 ]; then
  1376. CHIPSETt="\t\t\t\t\t\t"
  1377. # XXX YUP, 28 and 21 are now that same. mostly because this is all hardcoded and sucks
  1378. elif [ ${#CHIPSET} -gt 28 ]; then
  1379. CHIPSETt="\t\t\t\t\t\t\t"
  1380. elif [ ${#CHIPSET} -gt 21 ]; then
  1381. CHIPSETt="\t\t\t\t\t\t\t"
  1382. elif [ ${#CHIPSET} -gt 14 ]; then
  1383. CHIPSETt="\t\t\t\t\t\t\t\t"
  1384. elif [ ${#CHIPSET} -gt 7 ]; then
  1385. CHIPSETt="\t\t\t\t\t\t\t\t\t"
  1386. else
  1387. CHIPSETt="\t\t\t\t\t\t\t\t\t\t"
  1388. fi
  1389. fi
  1390. printf "${FROM}[${PHYDEV}]${iface}${FIELD1t}${DRIVER}[${STACK}]-${FIRMWARE}${FIELD2t}${CHIPSET}${CHIPSETt}${EXTENDED}\n"
  1391. else
  1392. #beautify output spacing (within reason, interface/driver max length is 15 and phy max length is 7))
  1393. if [ ${#DRIVER} -gt 7 ]; then
  1394. DRIVERt="\t"
  1395. else
  1396. DRIVERt="\t\t"
  1397. fi
  1398. if [ ${#iface} -gt 7 ]; then
  1399. ifacet="\t"
  1400. else
  1401. ifacet="\t\t"
  1402. fi
  1403. printf "${PHYDEV}\t${iface}${ifacet}${DRIVER}${DRIVERt}${CHIPSET}\n"
  1404. fi
  1405. if [ "$DRIVER" = "wl" ]; then
  1406. if [ "$1" = "start" ] && [ "$2" = "$iface" ]; then
  1407. startwlIface $iface
  1408. fi
  1409. if [ "$1" = "stop" ] && [ "$2" = "$iface" ]; then
  1410. stopwlIface $iface
  1411. fi
  1412. elif [ "$MAC80211" = "1" ]; then
  1413. if [ "$1" = "start" ] && [ "$2" = "$iface" ]; then
  1414. startMac80211Iface $iface
  1415. fi
  1416. if [ "$1" = "stop" ] && [ "$2" = "$iface" ]; then
  1417. stopMac80211Iface $iface
  1418. fi
  1419. fi
  1420. done
  1421. #end with some space
  1422. printf "\n"