/* * Linux cfg80211 driver - Android related functions * * Copyright (C) 1999-2013, Broadcom Corporation * * Unless you and Broadcom execute a separate written software license * agreement governing use of this software, this software is licensed to you * under the terms of the GNU General Public License version 2 (the "GPL"), * available at http://www.broadcom.com/licenses/GPLv2.php, with the * following added to such license: * * As a special exception, the copyright holders of this software give you * permission to link this software with independent modules, and to copy and * distribute the resulting executable under terms of your choice, provided that * you also meet, for each linked independent module, the terms and conditions of * the license of that module. An independent module is a module which is not * derived from this software. The special exception does not apply to any * modifications of the software. * * Notwithstanding the above, under no circumstances may you combine this * software in any way with any other Broadcom software provided under a license * other than the GPL, without Broadcom's express prior written consent. * * $Id: wl_android.c 442435 2013-12-11 09:03:27Z $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef PNO_SUPPORT #include #endif #include #ifdef WL_CFG80211 #include #endif #if defined(CONFIG_WIFI_CONTROL_FUNC) #include #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) #include #else #include #endif #endif /* CONFIG_WIFI_CONTROL_FUNC */ #include #include #include /* * Android private command strings, PLEASE define new private commands here * so they can be updated easily in the future (if needed) */ #define CMD_START "START" #define CMD_STOP "STOP" #define CMD_SCAN_ACTIVE "SCAN-ACTIVE" #define CMD_SCAN_PASSIVE "SCAN-PASSIVE" #define CMD_RSSI "RSSI" #define CMD_LINKSPEED "LINKSPEED" #ifdef PKT_FILTER_SUPPORT #define CMD_RXFILTER_START "RXFILTER-START" #define CMD_RXFILTER_STOP "RXFILTER-STOP" #define CMD_RXFILTER_ADD "RXFILTER-ADD" #define CMD_RXFILTER_REMOVE "RXFILTER-REMOVE" #endif /* PKT_FILTER_SUPPORT */ #define CMD_BTCOEXSCAN_START "BTCOEXSCAN-START" #define CMD_BTCOEXSCAN_STOP "BTCOEXSCAN-STOP" #define CMD_BTCOEXMODE "BTCOEXMODE" #define CMD_SETSUSPENDOPT "SETSUSPENDOPT" #define CMD_SETSUSPENDMODE "SETSUSPENDMODE" #define CMD_P2P_DEV_ADDR "P2P_DEV_ADDR" #define CMD_SETFWPATH "SETFWPATH" #define CMD_SETBAND "SETBAND" #define CMD_GETBAND "GETBAND" #define CMD_COUNTRY "COUNTRY" #define CMD_P2P_SET_NOA "P2P_SET_NOA" #if !defined WL_ENABLE_P2P_IF #define CMD_P2P_GET_NOA "P2P_GET_NOA" #endif /* WL_ENABLE_P2P_IF */ #define CMD_P2P_SD_OFFLOAD "P2P_SD_" #define CMD_P2P_SET_PS "P2P_SET_PS" #define CMD_SET_AP_WPS_P2P_IE "SET_AP_WPS_P2P_IE" #define CMD_SETROAMMODE "SETROAMMODE" #define CMD_SETIBSSBEACONOUIDATA "SETIBSSBEACONOUIDATA" #define CMD_MIRACAST "MIRACAST" #if defined(WL_SUPPORT_AUTO_CHANNEL) #define CMD_GET_BEST_CHANNELS "GET_BEST_CHANNELS" #endif /* WL_SUPPORT_AUTO_CHANNEL */ #define CMD_RTCOEX "MWS_COEX_BITMAP" /* CCX Private Commands */ #ifdef PNO_SUPPORT #define CMD_PNOSSIDCLR_SET "PNOSSIDCLR" #define CMD_PNOSETUP_SET "PNOSETUP " #define CMD_PNOENABLE_SET "PNOFORCE" #define CMD_PNODEBUG_SET "PNODEBUG" #define CMD_WLS_BATCHING "WLS_BATCHING" #endif /* PNO_SUPPORT */ #define CMD_OKC_SET_PMK "SET_PMK" #define CMD_OKC_ENABLE "OKC_ENABLE" #define CMD_HAPD_MAC_FILTER "HAPD_MAC_FILTER" /* hostap mac mode */ #define MACLIST_MODE_DISABLED 0 #define MACLIST_MODE_DENY 1 #define MACLIST_MODE_ALLOW 2 /* max number of assoc list */ #define MAX_NUM_OF_ASSOCLIST 64 /* max number of mac filter list * restrict max number to 10 as maximum cmd string size is 255 */ #define MAX_NUM_MAC_FILT 10 #ifdef CUSTOMER_HW10 #define CMD_KEEP_ALIVE "KEEPALIVE" #endif /* CUSTOMER_HW10 */ /* miracast related definition */ #define MIRACAST_MODE_OFF 0 #define MIRACAST_MODE_SOURCE 1 #define MIRACAST_MODE_SINK 2 #ifndef MIRACAST_AMPDU_SIZE #define MIRACAST_AMPDU_SIZE 8 #endif #ifndef MIRACAST_MCHAN_ALGO #define MIRACAST_MCHAN_ALGO 1 #endif #ifndef MIRACAST_MCHAN_BW #define MIRACAST_MCHAN_BW 25 #endif static LIST_HEAD(miracast_resume_list); static u8 miracast_cur_mode; struct io_cfg { s8 *iovar; s32 param; u32 ioctl; void *arg; u32 len; struct list_head list; }; typedef struct android_wifi_priv_cmd { char *buf; int used_len; int total_len; } android_wifi_priv_cmd; #ifdef CONFIG_COMPAT typedef struct compat_android_wifi_priv_cmd { compat_uptr_t buf; int used_len; int total_len; } compat_android_wifi_priv_cmd; #endif /* CONFIG_COMPAT */ /** * Extern function declarations (TODO: move them to dhd_linux.h) */ void dhd_customer_gpio_wlan_ctrl(int onoff); int dhd_dev_reset(struct net_device *dev, uint8 flag); int dhd_dev_init_ioctl(struct net_device *dev); #ifdef WL_CFG80211 int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr); int wl_cfg80211_set_btcoex_dhcp(struct net_device *dev, char *command); int wl_cfg80211_get_ioctl_version(void); #else int wl_cfg80211_get_p2p_dev_addr(struct net_device *net, struct ether_addr *p2pdev_addr) { return 0; } int wl_cfg80211_set_p2p_noa(struct net_device *net, char* buf, int len) { return 0; } int wl_cfg80211_get_p2p_noa(struct net_device *net, char* buf, int len) { return 0; } int wl_cfg80211_set_p2p_ps(struct net_device *net, char* buf, int len) { return 0; } #endif /* WK_CFG80211 */ extern int dhd_os_check_if_up(void *dhdp); #ifdef BCMLXSDMMC extern void *bcmsdh_get_drvdata(void); #endif /* BCMLXSDMMC */ #ifdef CUSTOMER_HW10 extern int wl_keep_alive_set(struct net_device *dev, char* extra, int total_len); #endif #ifdef ENABLE_4335BT_WAR extern int bcm_bt_lock(int cookie); extern void bcm_bt_unlock(int cookie); static int lock_cookie_wifi = 'W' | 'i'<<8 | 'F'<<16 | 'i'<<24; /* cookie is "WiFi" */ #endif /* ENABLE_4335BT_WAR */ char nv_id[30]; extern int bcmsdh_sdmmc_set_power(int on); extern bool ap_fw_loaded; #if defined(CUSTOMER_HW2) extern char iface_name[IFNAMSIZ]; #endif /** * Local (static) functions and variables */ /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first * time (only) in dhd_open, subsequential wifi on will be handled by * wl_android_wifi_on */ static int g_wifi_on = TRUE; /** * Local (static) function definitions */ static int wl_android_get_link_speed(struct net_device *net, char *command, int total_len) { int link_speed; int bytes_written; int error; error = wldev_get_link_speed(net, &link_speed); if (error) return -1; /* Convert Kbps to Android Mbps */ link_speed = link_speed / 1000; bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed); DHD_INFO(("%s: command result is %s\n", __FUNCTION__, command)); return bytes_written; } static int wl_android_get_rssi(struct net_device *net, char *command, int total_len) { wlc_ssid_t ssid = {0}; int rssi; int bytes_written = 0; int error; error = wldev_get_rssi(net, &rssi); //rssi = rssi + 10; //DHD_ERROR(("%s: RSSI is %d\n", __FUNCTION__, rssi)); if (error) return -1; error = wldev_get_ssid(net, &ssid); if (error) return -1; if ((ssid.SSID_len == 0) || (ssid.SSID_len > DOT11_MAX_SSID_LEN)) { DHD_ERROR(("%s: wldev_get_ssid failed\n", __FUNCTION__)); } else { memcpy(command, ssid.SSID, ssid.SSID_len); bytes_written = ssid.SSID_len; } bytes_written += snprintf(&command[bytes_written], total_len, " rssi %d", rssi); DHD_INFO(("%s: command result is %s (%d)\n", __FUNCTION__, command, bytes_written)); return bytes_written; } static int wl_android_set_suspendopt(struct net_device *dev, char *command, int total_len) { int suspend_flag; int ret_now; int ret = 0; suspend_flag = *(command + strlen(CMD_SETSUSPENDOPT) + 1) - '0'; if (suspend_flag != 0) suspend_flag = 1; ret_now = net_os_set_suspend_disable(dev, suspend_flag); if (ret_now != suspend_flag) { if (!(ret = net_os_set_suspend(dev, ret_now, 1))) DHD_INFO(("%s: Suspend Flag %d -> %d\n", __FUNCTION__, ret_now, suspend_flag)); else DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret)); } return ret; } static int wl_android_set_suspendmode(struct net_device *dev, char *command, int total_len) { int ret = 0; #if !defined(CONFIG_HAS_EARLYSUSPEND) || !defined(DHD_USE_EARLYSUSPEND) int suspend_flag; suspend_flag = *(command + strlen(CMD_SETSUSPENDMODE) + 1) - '0'; if (suspend_flag != 0) suspend_flag = 1; if (!(ret = net_os_set_suspend(dev, suspend_flag, 0))) DHD_INFO(("%s: Suspend Mode %d\n", __FUNCTION__, suspend_flag)); else DHD_ERROR(("%s: failed %d\n", __FUNCTION__, ret)); #endif return ret; } static int wl_android_get_band(struct net_device *dev, char *command, int total_len) { uint band; int bytes_written; int error; error = wldev_get_band(dev, &band); if (error) return -1; bytes_written = snprintf(command, total_len, "Band %d", band); return bytes_written; } #ifdef PNO_SUPPORT #define PNO_PARAM_SIZE 50 #define VALUE_SIZE 50 static int wls_parse_batching_cmd(struct net_device *dev, char *command, int total_len) { int err = BCME_OK; uint i, tokens; char *pos, *pos2, *token, *token2, *delim; char param[PNO_PARAM_SIZE], value[VALUE_SIZE]; struct dhd_pno_batch_params batch_params; DHD_PNO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len)); if (total_len < strlen(CMD_WLS_BATCHING)) { DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len)); err = BCME_ERROR; goto exit; } pos = command + strlen(CMD_WLS_BATCHING) + 1; memset(&batch_params, 0, sizeof(struct dhd_pno_batch_params)); if (!strncmp(pos, PNO_BATCHING_SET, strlen(PNO_BATCHING_SET))) { pos += strlen(PNO_BATCHING_SET) + 1; while ((token = strsep(&pos, PNO_PARAMS_DELIMETER)) != NULL) { memset(param, 0, sizeof(param)); memset(value, 0, sizeof(value)); if (token == NULL || !*token) break; if (*token == '\0') continue; delim = strchr(token, PNO_PARAM_VALUE_DELLIMETER); if (delim != NULL) *delim = ' '; tokens = sscanf(token, "%s %s", param, value); if (!strncmp(param, PNO_PARAM_SCANFREQ, strlen(PNO_PARAM_MSCAN))) { batch_params.scan_fr = simple_strtol(value, NULL, 0); DHD_PNO(("scan_freq : %d\n", batch_params.scan_fr)); } else if (!strncmp(param, PNO_PARAM_BESTN, strlen(PNO_PARAM_MSCAN))) { batch_params.bestn = simple_strtol(value, NULL, 0); DHD_PNO(("bestn : %d\n", batch_params.bestn)); } else if (!strncmp(param, PNO_PARAM_MSCAN, strlen(PNO_PARAM_MSCAN))) { batch_params.mscan = simple_strtol(value, NULL, 0); DHD_PNO(("mscan : %d\n", batch_params.mscan)); } else if (!strncmp(param, PNO_PARAM_CHANNEL, strlen(PNO_PARAM_MSCAN))) { i = 0; pos2 = value; tokens = sscanf(value, "<%s>", value); if (tokens != 1) { err = BCME_ERROR; DHD_ERROR(("%s : invalid format for channel" " <> params\n", __FUNCTION__)); goto exit; } while ((token2 = strsep(&pos2, PNO_PARAM_CHANNEL_DELIMETER)) != NULL) { if (token2 == NULL || !*token2) break; if (*token2 == '\0') continue; if (*token2 == 'A' || *token2 == 'B') { batch_params.band = (*token2 == 'A')? WLC_BAND_5G : WLC_BAND_2G; DHD_PNO(("band : %s\n", (*token2 == 'A')? "A" : "B")); } else { batch_params.chan_list[i++] = simple_strtol(token2, NULL, 0); batch_params.nchan++; DHD_PNO(("channel :%d\n", batch_params.chan_list[i-1])); } } } else if (!strncmp(param, PNO_PARAM_RTT, strlen(PNO_PARAM_MSCAN))) { batch_params.rtt = simple_strtol(value, NULL, 0); DHD_PNO(("rtt : %d\n", batch_params.rtt)); } else { DHD_ERROR(("%s : unknown param: %s\n", __FUNCTION__, param)); err = BCME_ERROR; goto exit; } } err = dhd_dev_pno_set_for_batch(dev, &batch_params); if (err < 0) { DHD_ERROR(("failed to configure batch scan\n")); } else { memset(command, 0, total_len); err = sprintf(command, "%d", err); } } else if (!strncmp(pos, PNO_BATCHING_GET, strlen(PNO_BATCHING_GET))) { err = dhd_dev_pno_get_for_batch(dev, command, total_len); if (err < 0) { DHD_ERROR(("failed to getting batching results\n")); } else { err = strlen(command); } } else if (!strncmp(pos, PNO_BATCHING_STOP, strlen(PNO_BATCHING_STOP))) { err = dhd_dev_pno_stop_for_batch(dev); if (err < 0) { DHD_ERROR(("failed to stop batching scan\n")); } else { memset(command, 0, total_len); err = sprintf(command, "OK"); } } else { DHD_ERROR(("%s : unknown command\n", __FUNCTION__)); err = BCME_ERROR; goto exit; } exit: return err; } #ifndef WL_SCHED_SCAN static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len) { wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT]; int res = -1; int nssid = 0; cmd_tlv_t *cmd_tlv_temp; char *str_ptr; int tlv_size_left; int pno_time = 0; int pno_repeat = 0; int pno_freq_expo_max = 0; #ifdef PNO_SET_DEBUG int i; char pno_in_example[] = { 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ', 'S', '1', '2', '0', 'S', 0x05, 'd', 'l', 'i', 'n', 'k', 'S', 0x04, 'G', 'O', 'O', 'G', 'T', '0', 'B', 'R', '2', 'M', '2', 0x00 }; #endif /* PNO_SET_DEBUG */ DHD_PNO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len)); if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) { DHD_ERROR(("%s argument=%d less min size\n", __FUNCTION__, total_len)); goto exit_proc; } #ifdef PNO_SET_DEBUG memcpy(command, pno_in_example, sizeof(pno_in_example)); total_len = sizeof(pno_in_example); #endif str_ptr = command + strlen(CMD_PNOSETUP_SET); tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET); cmd_tlv_temp = (cmd_tlv_t *)str_ptr; memset(ssids_local, 0, sizeof(ssids_local)); if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) && (cmd_tlv_temp->version == PNO_TLV_VERSION) && (cmd_tlv_temp->subtype == PNO_TLV_SUBTYPE_LEGACY_PNO)) { str_ptr += sizeof(cmd_tlv_t); tlv_size_left -= sizeof(cmd_tlv_t); if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local, MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) { DHD_ERROR(("SSID is not presented or corrupted ret=%d\n", nssid)); goto exit_proc; } else { if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) { DHD_ERROR(("%s scan duration corrupted field size %d\n", __FUNCTION__, tlv_size_left)); goto exit_proc; } str_ptr++; pno_time = simple_strtoul(str_ptr, &str_ptr, 16); DHD_PNO(("%s: pno_time=%d\n", __FUNCTION__, pno_time)); if (str_ptr[0] != 0) { if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) { DHD_ERROR(("%s pno repeat : corrupted field\n", __FUNCTION__)); goto exit_proc; } str_ptr++; pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16); DHD_PNO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat)); if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) { DHD_ERROR(("%s FREQ_EXPO_MAX corrupted field size\n", __FUNCTION__)); goto exit_proc; } str_ptr++; pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16); DHD_PNO(("%s: pno_freq_expo_max=%d\n", __FUNCTION__, pno_freq_expo_max)); } } } else { DHD_ERROR(("%s get wrong TLV command\n", __FUNCTION__)); goto exit_proc; } res = dhd_dev_pno_set_for_ssid(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max, NULL, 0); exit_proc: return res; } #endif /* !WL_SCHED_SCAN */ #endif /* PNO_SUPPORT */ static int wl_android_get_p2p_dev_addr(struct net_device *ndev, char *command, int total_len) { int ret; int bytes_written = 0; ret = wl_cfg80211_get_p2p_dev_addr(ndev, (struct ether_addr*)command); if (ret) return 0; bytes_written = sizeof(struct ether_addr); return bytes_written; } static int wl_android_set_ap_mac_list(struct net_device *dev, int macmode, struct maclist *maclist) { int i, j, match; int ret = 0; char mac_buf[MAX_NUM_OF_ASSOCLIST * sizeof(struct ether_addr) + sizeof(uint)] = {0}; struct maclist *assoc_maclist = (struct maclist *)mac_buf; /* set filtering mode */ if ((ret = wldev_ioctl(dev, WLC_SET_MACMODE, &macmode, sizeof(macmode), true)) != 0) { DHD_ERROR(("%s : WLC_SET_MACMODE error=%d\n", __FUNCTION__, ret)); return ret; } if (macmode != MACLIST_MODE_DISABLED) { /* set the MAC filter list */ if ((ret = wldev_ioctl(dev, WLC_SET_MACLIST, maclist, sizeof(int) + sizeof(struct ether_addr) * maclist->count, true)) != 0) { DHD_ERROR(("%s : WLC_SET_MACLIST error=%d\n", __FUNCTION__, ret)); return ret; } /* get the current list of associated STAs */ assoc_maclist->count = MAX_NUM_OF_ASSOCLIST; if ((ret = wldev_ioctl(dev, WLC_GET_ASSOCLIST, assoc_maclist, sizeof(mac_buf), false)) != 0) { DHD_ERROR(("%s : WLC_GET_ASSOCLIST error=%d\n", __FUNCTION__, ret)); return ret; } /* do we have any STA associated? */ if (assoc_maclist->count) { /* iterate each associated STA */ for (i = 0; i < assoc_maclist->count; i++) { match = 0; /* compare with each entry */ for (j = 0; j < maclist->count; j++) { DHD_INFO(("%s : associated="MACDBG " list="MACDBG "\n", __FUNCTION__, MAC2STRDBG(assoc_maclist->ea[i].octet), MAC2STRDBG(maclist->ea[j].octet))); if (memcmp(assoc_maclist->ea[i].octet, maclist->ea[j].octet, ETHER_ADDR_LEN) == 0) { match = 1; break; } } /* do conditional deauth */ /* "if not in the allow list" or "if in the deny list" */ if ((macmode == MACLIST_MODE_ALLOW && !match) || (macmode == MACLIST_MODE_DENY && match)) { scb_val_t scbval; scbval.val = htod32(1); memcpy(&scbval.ea, &assoc_maclist->ea[i], ETHER_ADDR_LEN); if ((ret = wldev_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval, sizeof(scb_val_t), true)) != 0) DHD_ERROR(("%s WLC_SCB_DEAUTHENTICATE error=%d\n", __FUNCTION__, ret)); } } } } return ret; } /* * HAPD_MAC_FILTER mac_mode mac_cnt mac_addr1 mac_addr2 * */ static int wl_android_set_mac_address_filter(struct net_device *dev, const char* str) { int i; int ret = 0; int macnum = 0; int macmode = MACLIST_MODE_DISABLED; struct maclist *list; char eabuf[ETHER_ADDR_STR_LEN]; /* string should look like below (macmode/macnum/maclist) */ /* 1 2 00:11:22:33:44:55 00:11:22:33:44:ff */ DHD_ERROR(("zhl %s : cmd=%s\n", __FUNCTION__, str)); /* get the MAC filter mode */ macmode = bcm_atoi(strsep((char**)&str, " ")); if (macmode < MACLIST_MODE_DISABLED || macmode > MACLIST_MODE_ALLOW) { DHD_ERROR(("%s : invalid macmode %d\n", __FUNCTION__, macmode)); return -1; } macnum = bcm_atoi(strsep((char**)&str, " ")); if (macnum < 0 || macnum > MAX_NUM_MAC_FILT) { DHD_ERROR(("%s : invalid number of MAC address entries %d\n", __FUNCTION__, macnum)); return -1; } /* allocate memory for the MAC list */ list = (struct maclist*)kmalloc(sizeof(int) + sizeof(struct ether_addr) * macnum, GFP_KERNEL); if (!list) { DHD_ERROR(("%s : failed to allocate memory\n", __FUNCTION__)); return -1; } /* prepare the MAC list */ list->count = htod32(macnum); bzero((char *)eabuf, ETHER_ADDR_STR_LEN); for (i = 0; i < list->count; i++) { strncpy(eabuf, strsep((char**)&str, " "), ETHER_ADDR_STR_LEN - 1); if (!(ret = bcm_ether_atoe(eabuf, &list->ea[i]))) { DHD_ERROR(("%s : mac parsing err index=%d, addr=%s\n", __FUNCTION__, i, eabuf)); list->count--; break; } DHD_INFO(("%s : %d/%d MACADDR=%s", __FUNCTION__, i, list->count, eabuf)); } /* set the list */ if ((ret = wl_android_set_ap_mac_list(dev, macmode, list)) != 0) DHD_ERROR(("%s : Setting MAC list failed error=%d\n", __FUNCTION__, ret)); kfree(list); return 0; } /** * Global function definitions (declared in wl_android.h) */ #define WIFI_ON_MAX_RETRY 3 int wl_android_wifi_on(struct net_device *dev) { int ret = 0; int retry = POWERUP_MAX_RETRY; int retry_wifi_on = WIFI_ON_MAX_RETRY; printk("%s in\n", __FUNCTION__); if (!dev) { DHD_ERROR(("%s: dev is null\n", __FUNCTION__)); return -EINVAL; } wifi_on: dhd_net_if_lock(dev); if (!g_wifi_on) { do { dhd_customer_gpio_wlan_ctrl(WLAN_RESET_ON); ret = sdioh_start(NULL, 0); if (ret == 0) break; DHD_ERROR(("\nfailed to power up wifi chip, retry again (%d left) **\n\n", retry+1)); dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF); } while (retry-- >= 0); if (ret != 0) { DHD_ERROR(("\nfailed to power up wifi chip, max retry reached **\n\n")); goto exit; } ret = dhd_dev_reset(dev, FALSE); sdioh_start(NULL, 1); if (!ret) { if (dhd_dev_init_ioctl(dev) < 0) ret = -EFAULT; } g_wifi_on = TRUE; } exit: dhd_net_if_unlock(dev); if (ret && --retry_wifi_on > 0) { DHD_ERROR(("\nRetry WIFI ON procedure (%d)\n\n", WIFI_ON_MAX_RETRY - retry_wifi_on)); wl_android_wifi_off(dev); goto wifi_on; } return ret; } int wl_android_wifi_off(struct net_device *dev) { int ret = 0; DHD_TRACE(("%s in\n", __FUNCTION__)); if (!dev) { DHD_TRACE(("%s: dev is null\n", __FUNCTION__)); return -EINVAL; } dhd_net_if_lock(dev); if (g_wifi_on) { ret = dhd_dev_reset(dev, TRUE); sdioh_stop(NULL); dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF); g_wifi_on = FALSE; } dhd_net_if_unlock(dev); return ret; } static int wl_android_set_fwpath(struct net_device *net, char *command, int total_len) { if ((strlen(command) - strlen(CMD_SETFWPATH)) > MOD_PARAM_PATHLEN) return -1; bcm_strncpy_s(fw_path, sizeof(fw_path), command + strlen(CMD_SETFWPATH) + 1, MOD_PARAM_PATHLEN - 1); if (strstr(fw_path, "apsta") != NULL) { DHD_INFO(("GOT APSTA FIRMWARE\n")); ap_fw_loaded = TRUE; } else { DHD_INFO(("GOT STA FIRMWARE\n")); ap_fw_loaded = FALSE; } return 0; } static int wl_android_set_pmk(struct net_device *dev, char *command, int total_len) { uchar pmk[33]; int error = 0; char smbuf[WLC_IOCTL_SMLEN]; #ifdef OKC_DEBUG int i = 0; #endif bzero(pmk, sizeof(pmk)); memcpy((char *)pmk, command + strlen("SET_PMK "), 32); error = wldev_iovar_setbuf(dev, "okc_info_pmk", pmk, 32, smbuf, sizeof(smbuf), NULL); if (error) { DHD_ERROR(("Failed to set PMK for OKC, error = %d\n", error)); } #ifdef OKC_DEBUG DHD_ERROR(("PMK is ")); for (i = 0; i < 32; i++) DHD_ERROR(("%02X ", pmk[i])); DHD_ERROR(("\n")); #endif return error; } static int wl_android_okc_enable(struct net_device *dev, char *command, int total_len) { int error = 0; char okc_enable = 0; okc_enable = command[strlen(CMD_OKC_ENABLE) + 1] - '0'; error = wldev_iovar_setint(dev, "okc_enable", okc_enable); if (error) { DHD_ERROR(("Failed to %s OKC, error = %d\n", okc_enable ? "enable" : "disable", error)); } wldev_iovar_setint(dev, "ccx_enable", 0); return error; } int wl_android_set_roam_mode(struct net_device *dev, char *command, int total_len) { int error = 0; int mode = 0; if (sscanf(command, "%*s %d", &mode) != 1) { DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__)); return -1; } error = wldev_iovar_setint(dev, "roam_off", mode); if (error) { DHD_ERROR(("%s: Failed to set roaming Mode %d, error = %d\n", __FUNCTION__, mode, error)); return -1; } else DHD_ERROR(("%s: succeeded to set roaming Mode %d, error = %d\n", __FUNCTION__, mode, error)); return 0; } int wl_android_set_ibss_beacon_ouidata(struct net_device *dev, char *command, int total_len) { char ie_buf[VNDR_IE_MAX_LEN]; char *ioctl_buf = NULL; char hex[] = "XX"; char *pcmd = NULL; int ielen = 0, datalen = 0, idx = 0, tot_len = 0; vndr_ie_setbuf_t *vndr_ie = NULL; s32 iecount; uint32 pktflag; u16 kflags = in_atomic() ? GFP_ATOMIC : GFP_KERNEL; s32 err = BCME_OK; /* Check the VSIE (Vendor Specific IE) which was added. * If exist then send IOVAR to delete it */ if (wl_cfg80211_ibss_vsie_delete(dev) != BCME_OK) { return -EINVAL; } pcmd = command + strlen(CMD_SETIBSSBEACONOUIDATA) + 1; for (idx = 0; idx < DOT11_OUI_LEN; idx++) { hex[0] = *pcmd++; hex[1] = *pcmd++; ie_buf[idx] = (uint8)simple_strtoul(hex, NULL, 16); } pcmd++; while ((*pcmd != '\0') && (idx < VNDR_IE_MAX_LEN)) { hex[0] = *pcmd++; hex[1] = *pcmd++; ie_buf[idx++] = (uint8)simple_strtoul(hex, NULL, 16); datalen++; } tot_len = sizeof(vndr_ie_setbuf_t) + (datalen - 1); vndr_ie = (vndr_ie_setbuf_t *) kzalloc(tot_len, kflags); if (!vndr_ie) { WL_ERR(("IE memory alloc failed\n")); return -ENOMEM; } /* Copy the vndr_ie SET command ("add"/"del") to the buffer */ strncpy(vndr_ie->cmd, "add", VNDR_IE_CMD_LEN - 1); vndr_ie->cmd[VNDR_IE_CMD_LEN - 1] = '\0'; /* Set the IE count - the buffer contains only 1 IE */ iecount = htod32(1); memcpy((void *)&vndr_ie->vndr_ie_buffer.iecount, &iecount, sizeof(s32)); /* Set packet flag to indicate that BEACON's will contain this IE */ pktflag = htod32(VNDR_IE_BEACON_FLAG | VNDR_IE_PRBRSP_FLAG); memcpy((void *)&vndr_ie->vndr_ie_buffer.vndr_ie_list[0].pktflag, &pktflag, sizeof(u32)); /* Set the IE ID */ vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.id = (uchar) DOT11_MNG_PROPR_ID; memcpy(&vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.oui, &ie_buf, DOT11_OUI_LEN); memcpy(&vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.data, &ie_buf[DOT11_OUI_LEN], datalen); ielen = DOT11_OUI_LEN + datalen; vndr_ie->vndr_ie_buffer.vndr_ie_list[0].vndr_ie_data.len = (uchar) ielen; ioctl_buf = kmalloc(WLC_IOCTL_MEDLEN, GFP_KERNEL); if (!ioctl_buf) { WL_ERR(("ioctl memory alloc failed\n")); if (vndr_ie) { kfree(vndr_ie); } return -ENOMEM; } memset(ioctl_buf, 0, WLC_IOCTL_MEDLEN); /* init the buffer */ err = wldev_iovar_setbuf(dev, "ie", vndr_ie, tot_len, ioctl_buf, WLC_IOCTL_MEDLEN, NULL); if (err != BCME_OK) { err = -EINVAL; if (vndr_ie) { kfree(vndr_ie); } } else { /* do NOT free 'vndr_ie' for the next process */ wl_cfg80211_ibss_vsie_set_buffer(vndr_ie, tot_len); } if (ioctl_buf) { kfree(ioctl_buf); } return err; } static int wl_android_iolist_add(struct net_device *dev, struct list_head *head, struct io_cfg *config) { struct io_cfg *resume_cfg; s32 ret; resume_cfg = kzalloc(sizeof(struct io_cfg), GFP_KERNEL); if (!resume_cfg) return -ENOMEM; if (config->iovar) { ret = wldev_iovar_getint(dev, config->iovar, &resume_cfg->param); if (ret) { DHD_ERROR(("%s: Failed to get current %s value\n", __FUNCTION__, config->iovar)); goto error; } ret = wldev_iovar_setint(dev, config->iovar, config->param); if (ret) { DHD_ERROR(("%s: Failed to set %s to %d\n", __FUNCTION__, config->iovar, config->param)); goto error; } resume_cfg->iovar = config->iovar; } else { resume_cfg->arg = kzalloc(config->len, GFP_KERNEL); if (!resume_cfg->arg) { ret = -ENOMEM; goto error; } ret = wldev_ioctl(dev, config->ioctl, resume_cfg->arg, config->len, false); if (ret) { DHD_ERROR(("%s: Failed to get ioctl %d\n", __FUNCTION__, config->ioctl)); goto error; } ret = wldev_ioctl(dev, config->ioctl + 1, config->arg, config->len, true); if (ret) { DHD_ERROR(("%s: Failed to set %s to %d\n", __FUNCTION__, config->iovar, config->param)); goto error; } if (config->ioctl + 1 == WLC_SET_PM) wl_cfg80211_update_power_mode(dev); resume_cfg->ioctl = config->ioctl; resume_cfg->len = config->len; } list_add(&resume_cfg->list, head); return 0; error: kfree(resume_cfg->arg); kfree(resume_cfg); return ret; } static void wl_android_iolist_resume(struct net_device *dev, struct list_head *head) { struct io_cfg *config; struct list_head *cur, *q; s32 ret = 0; list_for_each_safe(cur, q, head) { config = list_entry(cur, struct io_cfg, list); if (config->iovar) { if (!ret) ret = wldev_iovar_setint(dev, config->iovar, config->param); } else { if (!ret) ret = wldev_ioctl(dev, config->ioctl + 1, config->arg, config->len, true); if (config->ioctl + 1 == WLC_SET_PM) wl_cfg80211_update_power_mode(dev); kfree(config->arg); } list_del(cur); kfree(config); } } static int wl_android_set_miracast(struct net_device *dev, char *command, int total_len) { int mode, val; int ret = 0; struct io_cfg config; if (sscanf(command, "%*s %d", &mode) != 1) { DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__)); return -1; } DHD_INFO(("%s: enter miracast mode %d\n", __FUNCTION__, mode)); if (miracast_cur_mode == mode) return 0; wl_android_iolist_resume(dev, &miracast_resume_list); miracast_cur_mode = MIRACAST_MODE_OFF; switch (mode) { case MIRACAST_MODE_SOURCE: /* setting mchan_algo to platform specific value */ config.iovar = "mchan_algo"; config.param = MIRACAST_MCHAN_ALGO; ret = wl_android_iolist_add(dev, &miracast_resume_list, &config); if (ret) goto resume; /* setting mchan_bw to platform specific value */ config.iovar = "mchan_bw"; config.param = MIRACAST_MCHAN_BW; ret = wl_android_iolist_add(dev, &miracast_resume_list, &config); if (ret) goto resume; /* setting apmdu to platform specific value */ config.iovar = "ampdu_mpdu"; config.param = MIRACAST_AMPDU_SIZE; ret = wl_android_iolist_add(dev, &miracast_resume_list, &config); if (ret) goto resume; /* FALLTROUGH */ /* Source mode shares most configurations with sink mode. * Fall through here to avoid code duplication */ case MIRACAST_MODE_SINK: /* disable internal roaming */ config.iovar = "roam_off"; config.param = 1; ret = wl_android_iolist_add(dev, &miracast_resume_list, &config); if (ret) goto resume; /* tunr off pm */ val = 0; config.iovar = NULL; config.ioctl = WLC_GET_PM; config.arg = &val; config.len = sizeof(int); ret = wl_android_iolist_add(dev, &miracast_resume_list, &config); if (ret) goto resume; break; case MIRACAST_MODE_OFF: default: break; } miracast_cur_mode = mode; return 0; resume: DHD_ERROR(("%s: turnoff miracast mode because of err%d\n", __FUNCTION__, ret)); wl_android_iolist_resume(dev, &miracast_resume_list); return ret; } int wl_android_set_rt_coex(struct net_device *dev, char *command, int total_len) { int error = 0; int bitmap = 0; if (sscanf(command, "%*s %x", &bitmap) != 1) { DHD_ERROR(("%s: Failed to get Parameter\n", __FUNCTION__)); return -1; } error = wldev_iovar_setint(dev, "mws_coex_bitmap", bitmap); if (error) { DHD_ERROR(("%s: Failed to set rt coex bitmap %x, error = %d\n", __FUNCTION__, bitmap, error)); return -1; } else DHD_ERROR(("%s: succeeded to set rt coex bitmap %x, error = %d\n", __FUNCTION__, bitmap, error)); return 0; } int wl_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd) { #define PRIVATE_COMMAND_MAX_LEN 8192 int ret = 0; char *command = NULL; int bytes_written = 0; android_wifi_priv_cmd priv_cmd; net_os_wake_lock(net); if (!ifr->ifr_data) { ret = -EINVAL; goto exit; } #ifdef CONFIG_COMPAT if (is_compat_task()) { /* User space is 32-bit, use compat ioctl */ compat_android_wifi_priv_cmd compat_priv_cmd; if (copy_from_user(&compat_priv_cmd, ifr->ifr_data, sizeof(compat_android_wifi_priv_cmd))) { ret = -EFAULT; goto exit; } priv_cmd.buf = compat_ptr(compat_priv_cmd.buf); priv_cmd.used_len = compat_priv_cmd.used_len; priv_cmd.total_len = compat_priv_cmd.total_len; } else #endif /* CONFIG_COMPAT */ if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) { ret = -EFAULT; goto exit; } if (priv_cmd.total_len > PRIVATE_COMMAND_MAX_LEN) { DHD_ERROR(("%s: too long priavte command\n", __FUNCTION__)); ret = -EINVAL; goto exit; } command = kmalloc((priv_cmd.total_len + 1), GFP_KERNEL); if (!command) { DHD_ERROR(("%s: failed to allocate memory\n", __FUNCTION__)); ret = -ENOMEM; goto exit; } if (copy_from_user(command, priv_cmd.buf, priv_cmd.total_len)) { ret = -EFAULT; goto exit; } command[priv_cmd.total_len] = '\0'; DHD_INFO(("%s: Android private cmd \"%s\" on %s\n", __FUNCTION__, command, ifr->ifr_name)); if (strnicmp(command, CMD_START, strlen(CMD_START)) == 0) { DHD_INFO(("%s, Received regular START command\n", __FUNCTION__)); bytes_written = wl_android_wifi_on(net); } else if (strnicmp(command, CMD_SETFWPATH, strlen(CMD_SETFWPATH)) == 0) { bytes_written = wl_android_set_fwpath(net, command, priv_cmd.total_len); } if (!g_wifi_on) { DHD_ERROR(("%s: Ignore private cmd \"%s\" - iface %s is down\n", __FUNCTION__, command, ifr->ifr_name)); ret = 0; goto exit; } if (strnicmp(command, CMD_STOP, strlen(CMD_STOP)) == 0) { bytes_written = wl_android_wifi_off(net); } else if (strnicmp(command, CMD_SCAN_ACTIVE, strlen(CMD_SCAN_ACTIVE)) == 0) { /* TBD: SCAN-ACTIVE */ } else if (strnicmp(command, CMD_SCAN_PASSIVE, strlen(CMD_SCAN_PASSIVE)) == 0) { /* TBD: SCAN-PASSIVE */ } else if (strnicmp(command, CMD_RSSI, strlen(CMD_RSSI)) == 0) { bytes_written = wl_android_get_rssi(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_LINKSPEED, strlen(CMD_LINKSPEED)) == 0) { bytes_written = wl_android_get_link_speed(net, command, priv_cmd.total_len); } #ifdef PKT_FILTER_SUPPORT else if (strnicmp(command, CMD_RXFILTER_START, strlen(CMD_RXFILTER_START)) == 0) { bytes_written = net_os_enable_packet_filter(net, 1); } else if (strnicmp(command, CMD_RXFILTER_STOP, strlen(CMD_RXFILTER_STOP)) == 0) { bytes_written = net_os_enable_packet_filter(net, 0); } else if (strnicmp(command, CMD_RXFILTER_ADD, strlen(CMD_RXFILTER_ADD)) == 0) { int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0'; bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num); } else if (strnicmp(command, CMD_RXFILTER_REMOVE, strlen(CMD_RXFILTER_REMOVE)) == 0) { int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0'; bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num); } #endif /* PKT_FILTER_SUPPORT */ else if (strnicmp(command, CMD_BTCOEXSCAN_START, strlen(CMD_BTCOEXSCAN_START)) == 0) { /* TBD: BTCOEXSCAN-START */ } else if (strnicmp(command, CMD_BTCOEXSCAN_STOP, strlen(CMD_BTCOEXSCAN_STOP)) == 0) { /* TBD: BTCOEXSCAN-STOP */ } else if (strnicmp(command, CMD_BTCOEXMODE, strlen(CMD_BTCOEXMODE)) == 0) { #ifdef WL_CFG80211 bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command); #else #ifdef PKT_FILTER_SUPPORT uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0'; if (mode == 1) net_os_enable_packet_filter(net, 0); /* DHCP starts */ else net_os_enable_packet_filter(net, 1); /* DHCP ends */ #endif /* PKT_FILTER_SUPPORT */ #endif /* WL_CFG80211 */ } else if (strnicmp(command, CMD_SETSUSPENDOPT, strlen(CMD_SETSUSPENDOPT)) == 0) { bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_SETSUSPENDMODE, strlen(CMD_SETSUSPENDMODE)) == 0) { bytes_written = wl_android_set_suspendmode(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_SETBAND, strlen(CMD_SETBAND)) == 0) { uint band = *(command + strlen(CMD_SETBAND) + 1) - '0'; bytes_written = wldev_set_band(net, band); } else if (strnicmp(command, CMD_GETBAND, strlen(CMD_GETBAND)) == 0) { bytes_written = wl_android_get_band(net, command, priv_cmd.total_len); } #ifdef WL_CFG80211 /* CUSTOMER_SET_COUNTRY feature is define for only GGSM model */ else if (strnicmp(command, CMD_COUNTRY, strlen(CMD_COUNTRY)) == 0) { char *country_code = command + strlen(CMD_COUNTRY) + 1; bytes_written = wldev_set_country(net, country_code, true, true); } #endif /* WL_CFG80211 */ #ifdef PNO_SUPPORT else if (strnicmp(command, CMD_PNOSSIDCLR_SET, strlen(CMD_PNOSSIDCLR_SET)) == 0) { bytes_written = dhd_dev_pno_stop_for_ssid(net); } #ifndef WL_SCHED_SCAN else if (strnicmp(command, CMD_PNOSETUP_SET, strlen(CMD_PNOSETUP_SET)) == 0) { bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len); } #endif /* !WL_SCHED_SCAN */ else if (strnicmp(command, CMD_PNOENABLE_SET, strlen(CMD_PNOENABLE_SET)) == 0) { int enable = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0'; bytes_written = (enable)? 0 : dhd_dev_pno_stop_for_ssid(net); } else if (strnicmp(command, CMD_WLS_BATCHING, strlen(CMD_WLS_BATCHING)) == 0) { bytes_written = wls_parse_batching_cmd(net, command, priv_cmd.total_len); } #endif /* PNO_SUPPORT */ else if (strnicmp(command, CMD_P2P_DEV_ADDR, strlen(CMD_P2P_DEV_ADDR)) == 0) { bytes_written = wl_android_get_p2p_dev_addr(net, command, priv_cmd.total_len); } else if (strnicmp(command, CMD_P2P_SET_NOA, strlen(CMD_P2P_SET_NOA)) == 0) { int skip = strlen(CMD_P2P_SET_NOA) + 1; bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip, priv_cmd.total_len - skip); } #if !defined WL_ENABLE_P2P_IF else if (strnicmp(command, CMD_P2P_GET_NOA, strlen(CMD_P2P_GET_NOA)) == 0) { bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len); } #endif /* WL_ENABLE_P2P_IF */ else if (strnicmp(command, CMD_P2P_SET_PS, strlen(CMD_P2P_SET_PS)) == 0) { int skip = strlen(CMD_P2P_SET_PS) + 1; bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip, priv_cmd.total_len - skip); } #ifdef WL_CFG80211 else if (strnicmp(command, CMD_SET_AP_WPS_P2P_IE, strlen(CMD_SET_AP_WPS_P2P_IE)) == 0) { int skip = strlen(CMD_SET_AP_WPS_P2P_IE) + 3; bytes_written = wl_cfg80211_set_wps_p2p_ie(net, command + skip, priv_cmd.total_len - skip, *(command + skip - 2) - '0'); } #endif /* WL_CFG80211 */ else if (strnicmp(command, CMD_OKC_SET_PMK, strlen(CMD_OKC_SET_PMK)) == 0) bytes_written = wl_android_set_pmk(net, command, priv_cmd.total_len); else if (strnicmp(command, CMD_OKC_ENABLE, strlen(CMD_OKC_ENABLE)) == 0) bytes_written = wl_android_okc_enable(net, command, priv_cmd.total_len); #if defined(WL_SUPPORT_AUTO_CHANNEL) else if (strnicmp(command, CMD_GET_BEST_CHANNELS, strlen(CMD_GET_BEST_CHANNELS)) == 0) { bytes_written = wl_cfg80211_get_best_channels(net, command, priv_cmd.total_len); } #endif /* WL_SUPPORT_AUTO_CHANNEL */ else if (strnicmp(command, CMD_HAPD_MAC_FILTER, strlen(CMD_HAPD_MAC_FILTER)) == 0) { int skip = strlen(CMD_HAPD_MAC_FILTER) + 1; wl_android_set_mac_address_filter(net, (const char*)command+skip); } else if (strnicmp(command, CMD_SETROAMMODE, strlen(CMD_SETROAMMODE)) == 0) bytes_written = wl_android_set_roam_mode(net, command, priv_cmd.total_len); else if (strnicmp(command, CMD_MIRACAST, strlen(CMD_MIRACAST)) == 0) bytes_written = wl_android_set_miracast(net, command, priv_cmd.total_len); else if (strnicmp(command, CMD_SETIBSSBEACONOUIDATA, strlen(CMD_SETIBSSBEACONOUIDATA)) == 0) bytes_written = wl_android_set_ibss_beacon_ouidata(net, command, priv_cmd.total_len); else if (strnicmp(command, CMD_RTCOEX, strlen(CMD_RTCOEX)) == 0) bytes_written = wl_android_set_rt_coex(net, command, priv_cmd.total_len); else { DHD_ERROR(("Unknown PRIVATE command %s - ignored\n", command)); snprintf(command, 3, "OK"); bytes_written = strlen("OK"); } if (bytes_written >= 0) { if ((bytes_written == 0) && (priv_cmd.total_len > 0)) command[0] = '\0'; if (bytes_written >= priv_cmd.total_len) { DHD_ERROR(("%s: bytes_written = %d\n", __FUNCTION__, bytes_written)); bytes_written = priv_cmd.total_len; } else { bytes_written++; } priv_cmd.used_len = bytes_written; if (copy_to_user(priv_cmd.buf, command, bytes_written)) { DHD_ERROR(("%s: failed to copy data to user buffer\n", __FUNCTION__)); ret = -EFAULT; } } else { ret = bytes_written; } exit: net_os_wake_unlock(net); if (command) { kfree(command); } return ret; } int wl_android_init(void) { int ret = 0; #ifdef ENABLE_INSMOD_NO_FW_LOAD dhd_download_fw_on_driverload = FALSE; #endif /* ENABLE_INSMOD_NO_FW_LOAD */ #if defined(CUSTOMER_HW2) if (!iface_name[0]) { memset(iface_name, 0, IFNAMSIZ); bcm_strncpy_s(iface_name, IFNAMSIZ, "wlan", IFNAMSIZ); } #endif return ret; } int wl_android_exit(void) { int ret = 0; return ret; } void wl_android_post_init(void) { #ifdef ENABLE_4335BT_WAR bcm_bt_unlock(lock_cookie_wifi); printk("%s: btlock released\n", __FUNCTION__); #endif /* ENABLE_4335BT_WAR */ if (!dhd_download_fw_on_driverload) { /* Call customer gpio to turn off power with WL_REG_ON signal */ dhd_customer_gpio_wlan_ctrl(WLAN_RESET_OFF); g_wifi_on = FALSE; } } /** * Functions for Android WiFi card detection */ #if defined(CONFIG_WIFI_CONTROL_FUNC) bool g_wifi_poweron = FALSE; static int g_wifidev_registered = 0; static struct semaphore wifi_control_sem; static struct wifi_platform_data *wifi_control_data = NULL; static struct resource *wifi_irqres = NULL; static struct regulator *wifi_regulator = NULL; static struct resource *wifi_gpioenres; static int wifi_add_dev(void); static void wifi_del_dev(void); int wl_android_wifictrl_func_add(void) { int ret = 0; sema_init(&wifi_control_sem, 0); ret = wifi_add_dev(); if (ret) { DHD_ERROR(("%s: platform_driver_register failed\n", __FUNCTION__)); return ret; } g_wifidev_registered = 1; /* Waiting callback after platform_driver_register is done or exit with error */ if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) { ret = -EINVAL; DHD_ERROR(("%s: platform_driver_register timeout\n", __FUNCTION__)); } return ret; } void wl_android_wifictrl_func_del(void) { if (g_wifidev_registered) { wifi_del_dev(); g_wifidev_registered = 0; } } void* wl_android_prealloc(int section, unsigned long size) { void *alloc_ptr = NULL; if (wifi_control_data && wifi_control_data->mem_prealloc) { alloc_ptr = wifi_control_data->mem_prealloc(section, size); if (alloc_ptr) { DHD_INFO(("success alloc section %d\n", section)); if (size != 0L) bzero(alloc_ptr, size); return alloc_ptr; } } DHD_ERROR(("can't alloc section %d\n", section)); return NULL; } int wifi_get_irq_number(unsigned long *irq_flags_ptr) { if (wifi_irqres) { *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK; return (int)wifi_irqres->start; } #ifdef CUSTOM_OOB_GPIO_NUM return CUSTOM_OOB_GPIO_NUM; #else return -1; #endif } int wifi_get_gpioen_number(void) { if (wifi_gpioenres) return (int)wifi_gpioenres->start; return -1; } bool wifi_irq_is_fastirq(void) { if (wifi_control_data) return wifi_control_data->use_fast_irq; return false; } int wifi_set_power(int on, unsigned long msec) { int ret = 0; DHD_ERROR(("%s = %d\n", __FUNCTION__, on)); #ifdef ENABLE_4335BT_WAR if (on) { pr_err("WiFi: trying to acquire BT lock\n"); if (bcm_bt_lock(lock_cookie_wifi) != 0) printk("** WiFi: timeout in acquiring bt lock**\n"); pr_err("%s: btlock acquired\n", __FUNCTION__); } else { /* For a exceptional case, release btlock */ bcm_bt_unlock(lock_cookie_wifi); } #endif /* ENABLE_4335BT_WAR */ if (wifi_regulator && on) ret = regulator_enable(wifi_regulator); if (wifi_control_data && wifi_control_data->set_power) { ret = wifi_control_data->set_power(on); } else { bcmsdh_sdmmc_set_power(on); } if (wifi_regulator && !on) ret = regulator_disable(wifi_regulator); if (msec && !ret) OSL_SLEEP(msec); return ret; } #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) int wifi_get_mac_addr(unsigned char *buf) { DHD_ERROR(("%s\n", __FUNCTION__)); if (!buf) return -EINVAL; if (wifi_control_data && wifi_control_data->get_mac_addr) { return wifi_control_data->get_mac_addr(buf); } return -EOPNOTSUPP; } #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) void *wifi_get_country_code(char *ccode) { DHD_TRACE(("%s\n", __FUNCTION__)); if (!ccode) return NULL; if (wifi_control_data && wifi_control_data->get_country_code) { return wifi_control_data->get_country_code(ccode); } return NULL; } #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */ static void generate_nvram_id(void) { strncpy(nv_id, "aob", sizeof(nv_id)); nv_id[sizeof(nv_id) - 1] = '\0'; } static struct resource *get_wifi_irqres_from_of(struct platform_device *pdev) { static struct resource gpio_wifi_irqres; int irq; int gpio = of_get_gpio(pdev->dev.of_node, 0); if (gpio < 0) return NULL; irq = gpio_to_irq(gpio); if (irq < 0) return NULL; gpio_wifi_irqres.name = "bcmdhd_wlan_irq"; gpio_wifi_irqres.start = irq; gpio_wifi_irqres.end = irq; gpio_wifi_irqres.flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL | IORESOURCE_IRQ_SHAREABLE; return &gpio_wifi_irqres; } static int wifi_probe(struct platform_device *pdev) { struct wifi_platform_data *wifi_ctrl = (struct wifi_platform_data *)(pdev->dev.platform_data); #ifdef CONFIG_ACPI acpi_handle handle; struct acpi_device *adev; #endif wifi_irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0); if (wifi_irqres == NULL) wifi_irqres = get_wifi_irqres_from_of(pdev); if (wifi_irqres == NULL) { pr_err("WiFi: unable to get wifi_irqres !\n"); return -ENODATA; } if (ACPI_HANDLE(&pdev->dev)) { #ifdef CONFIG_ACPI handle = ACPI_HANDLE(&pdev->dev); /* Dont try to do acpi pm for the wifi module */ if (!handle || acpi_bus_get_device(handle, &adev)) pr_info("bcm probe: could not get acpi pointer!\n"); else adev->flags.power_manageable = 0; #endif wifi_irqres->start = acpi_get_gpio_by_index(&pdev->dev, 0, NULL); pr_info("bcm probe: Using ACPI table to get IRQ number: %d\n", (int)wifi_irqres->start); if ((int)wifi_irqres->start < 0) { if (INTEL_MID_BOARD(2, TABLET, BYT, BLB, PRO) || INTEL_MID_BOARD(2, TABLET, BYT, BLB, ENG)) { pr_info("bcm probe: BYT-M hardcoding\n"); wifi_irqres->start = acpi_get_gpio("\\_SB.GPO2", 17); } else { pr_info("bcm probe: BYT-T hardcoding\n"); wifi_irqres->start = acpi_get_gpio("\\_SB.GPO2", 15); } } } else pr_info("bcm probe: Using SFI table to get IRQ number: %d", (int)wifi_irqres->start ); /* Fill platform data (for potential needs) */ if (wifi_control_data == NULL && wifi_ctrl != NULL) wifi_control_data = wifi_ctrl; generate_nvram_id(); g_wifi_poweron = TRUE; up(&wifi_control_sem); return 0; } static int wifi_remove(struct platform_device *pdev) { struct wifi_platform_data *wifi_ctrl = (struct wifi_platform_data *)(pdev->dev.platform_data); struct io_cfg *cur, *q; DHD_ERROR(("## %s\n", __FUNCTION__)); wifi_control_data = wifi_ctrl; g_wifi_poweron = FALSE; list_for_each_entry_safe(cur, q, &miracast_resume_list, list) { list_del(&cur->list); kfree(cur); } if (wifi_regulator) { regulator_put(wifi_regulator); wifi_regulator = NULL; } up(&wifi_control_sem); return 0; } static int wifi_suspend(struct platform_device *pdev, pm_message_t state) { DHD_TRACE(("##> %s\n", __FUNCTION__)); #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY) && 1 bcmsdh_oob_intr_set(0); #endif /* (OOB_INTR_ONLY) */ return 0; } static int wifi_resume(struct platform_device *pdev) { DHD_TRACE(("##> %s\n", __FUNCTION__)); #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY) && 1 if (dhd_os_check_if_up(bcmsdh_get_drvdata())) bcmsdh_oob_intr_set(1); #endif /* (OOB_INTR_ONLY) */ return 0; } #ifdef CONFIG_ACPI static struct acpi_device_id bcm_acpi_id[] = { /* ACPI IDs here */ { "BCM43241" }, { } }; MODULE_DEVICE_TABLE(acpi, bcm_acpi_id); #endif static const struct of_device_id wifi_device_dt_match[] = { { .compatible = "android,bcmdhd_wlan", }, {}, }; MODULE_DEVICE_TABLE(of, wifi_device_dt_match); static struct platform_driver wifi_device = { .probe = wifi_probe, .remove = wifi_remove, .suspend = wifi_suspend, .resume = wifi_resume, .driver = { #ifdef CONFIG_ACPI .acpi_match_table = ACPI_PTR(bcm_acpi_id), #endif .name = "wlan", .of_match_table = wifi_device_dt_match, } }; static struct platform_driver wifi_device_legacy = { .probe = wifi_probe, .remove = wifi_remove, .suspend = wifi_suspend, .resume = wifi_resume, .driver = { .name = "bcm4329_wlan", } }; static int wifi_add_dev(void) { int ret = 0; DHD_TRACE(("## Calling platform_driver_register\n")); ret = platform_driver_register(&wifi_device); if (ret) return ret; ret = platform_driver_register(&wifi_device_legacy); return ret; } static void wifi_del_dev(void) { DHD_TRACE(("## Unregister platform_driver_register\n")); platform_driver_unregister(&wifi_device); platform_driver_unregister(&wifi_device_legacy); } #endif /* defined(CONFIG_WIFI_CONTROL_FUNC) */