| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- /* Firmware/driver-layer dispatch: see wifi_fw.h. */
- #include "wifi_fw.h"
- #include "iwl_dvm.h"
- #include "iwl_mvm.h"
- #include "iwl_trans.h"
- #include "rtl8821au.h"
- enum { BE_NONE, BE_MVM, BE_DVM, BE_RTL };
- static int be; /* backend of the radio that is up (or last up) */
- /* Which backend would come up now. */
- static int pick(void)
- {
- if (rtl8821au_present())
- return BE_RTL;
- if (iwl_probe() == 0)
- return iwl_is_dvm() ? BE_DVM : BE_MVM;
- return BE_NONE;
- }
- /* The backend for calls that need a device: the active one, else the one
- * that would be picked. */
- static int cur(void)
- {
- return be != BE_NONE ? be : pick();
- }
- int wififw_probe(void)
- {
- return pick() == BE_NONE ? -1 : 0;
- }
- int wififw_present(void)
- {
- return cur() == BE_RTL ? rtl8821au_present() : iwl_present();
- }
- /* No probing here: SYS_NET_INFO asks once a second, and iwl_probe() scans
- * the whole PCI bus when no Intel card exists. */
- const char *wififw_chip_name(void)
- {
- int b = be;
- if (b == BE_NONE)
- b = rtl8821au_present() ? BE_RTL :
- iwl_present() ? BE_MVM : BE_NONE;
- switch (b) {
- case BE_RTL:
- return rtl8821au_chip_name();
- case BE_MVM:
- case BE_DVM:
- return iwl_chip_name();
- }
- return "none";
- }
- const char *wififw_fw_name(void)
- {
- const struct iwl_fw_info *fw;
- if (cur() == BE_RTL)
- return rtl8821au_fw_name();
- fw = iwl_fw();
- return fw && fw->present ? fw->human : "";
- }
- int wififw_fatal(void)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_fatal();
- case BE_MVM:
- case BE_DVM:
- return iwl_fatal();
- }
- return 0;
- }
- int wififw_up(unsigned char mac[6])
- {
- be = pick();
- switch (be) {
- case BE_RTL:
- return rtl8821au_up(mac);
- case BE_DVM:
- return iwl_dvm_up(mac);
- case BE_MVM:
- return iwl_mvm_up(mac);
- }
- return -1;
- }
- void wififw_down(void)
- {
- switch (be) {
- case BE_RTL:
- rtl8821au_down();
- break;
- case BE_DVM:
- iwl_dvm_down();
- break;
- case BE_MVM:
- iwl_mvm_down();
- break;
- }
- be = BE_NONE;
- }
- void wififw_shutdown(void)
- {
- int was = be;
- wififw_down();
- /* The Intel card may have run before the stick was plugged in: its
- * RX ring must stop writing into pages the next kernel reuses. */
- if (was != BE_MVM && was != BE_DVM && iwl_present()) {
- if (iwl_is_dvm())
- iwl_dvm_down();
- else
- iwl_mvm_down();
- }
- }
- const char *wififw_state(void)
- {
- switch (cur()) {
- case BE_RTL:
- return rtl8821au_state();
- case BE_DVM:
- return iwl_dvm_state();
- case BE_MVM:
- return iwl_mvm_state();
- }
- return "no WiFi device";
- }
- int wififw_poll(void)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_poll();
- case BE_DVM:
- return iwl_dvm_poll();
- case BE_MVM:
- return iwl_mvm_poll();
- }
- return -1;
- }
- int wififw_scan_start(void)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_scan_start();
- case BE_DVM:
- return iwl_dvm_scan_start();
- case BE_MVM:
- return iwl_mvm_scan_start();
- }
- return -1;
- }
- int wififw_scan_running(void)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_scan_running();
- case BE_DVM:
- return iwl_dvm_scan_running();
- case BE_MVM:
- return iwl_mvm_scan_running();
- }
- return 0;
- }
- int wififw_prepare_connect(const unsigned char bssid[6], unsigned int chan,
- unsigned int beacon_int)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_prepare_connect(bssid, chan, beacon_int);
- case BE_DVM:
- return iwl_dvm_prepare_connect(bssid, chan, beacon_int);
- case BE_MVM:
- return iwl_mvm_prepare_connect(bssid, chan, beacon_int);
- }
- return -1;
- }
- int wififw_set_assoc(unsigned short aid, unsigned int beacon_int,
- unsigned int dtim)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_set_assoc(aid, beacon_int, dtim);
- case BE_DVM:
- return iwl_dvm_set_assoc(aid, beacon_int, dtim);
- case BE_MVM:
- return iwl_mvm_set_assoc(aid, beacon_int, dtim);
- }
- return -1;
- }
- void wififw_disconnect(void)
- {
- switch (be) {
- case BE_RTL:
- rtl8821au_disconnect();
- break;
- case BE_DVM:
- iwl_dvm_disconnect();
- break;
- case BE_MVM:
- iwl_mvm_disconnect();
- break;
- }
- }
- int wififw_tx_mgmt(const unsigned char *frame, unsigned int len)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_tx_mgmt(frame, len);
- case BE_DVM:
- return iwl_dvm_tx_mgmt(frame, len);
- case BE_MVM:
- return iwl_mvm_tx_mgmt(frame, len);
- }
- return -1;
- }
- int wififw_tx_data(const unsigned char *frame, unsigned int len, int protect)
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_tx_data(frame, len, protect);
- case BE_DVM:
- return iwl_dvm_tx_data(frame, len, protect);
- case BE_MVM:
- return iwl_mvm_tx_data(frame, len, protect);
- }
- return -1;
- }
- int wififw_set_key(int pairwise, int keyidx, const unsigned char key[16],
- const unsigned char rsc[6])
- {
- switch (be) {
- case BE_RTL:
- return rtl8821au_set_key(pairwise, keyidx, key, rsc);
- case BE_DVM:
- return iwl_dvm_set_key(pairwise, keyidx, key, rsc);
- case BE_MVM:
- return iwl_mvm_set_key(pairwise, keyidx, key, rsc);
- }
- return -1;
- }
- void wififw_clear_keys(void)
- {
- switch (be) {
- case BE_RTL:
- rtl8821au_clear_keys();
- break;
- case BE_DVM:
- iwl_dvm_clear_keys();
- break;
- case BE_MVM:
- iwl_mvm_clear_keys();
- break;
- }
- }
|