rtw_android.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2017 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. *****************************************************************************/
  15. #ifdef CONFIG_GPIO_WAKEUP
  16. #include <linux/gpio.h>
  17. #endif
  18. #include <drv_types.h>
  19. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  20. #include <linux/platform_device.h>
  21. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  22. #include <linux/wlan_plat.h>
  23. #else
  24. #include <linux/wifi_tiwlan.h>
  25. #endif
  26. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */
  27. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
  28. #define strnicmp strncasecmp
  29. #endif /* Linux kernel >= 4.0.0 */
  30. #ifdef CONFIG_GPIO_WAKEUP
  31. #include <linux/interrupt.h>
  32. #include <linux/irq.h>
  33. #endif
  34. #include "rtw_version.h"
  35. extern void macstr2num(u8 *dst, u8 *src);
  36. const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
  37. "START",
  38. "STOP",
  39. "SCAN-ACTIVE",
  40. "SCAN-PASSIVE",
  41. "RSSI",
  42. "LINKSPEED",
  43. "RXFILTER-START",
  44. "RXFILTER-STOP",
  45. "RXFILTER-ADD",
  46. "RXFILTER-REMOVE",
  47. "BTCOEXSCAN-START",
  48. "BTCOEXSCAN-STOP",
  49. "BTCOEXMODE",
  50. "SETSUSPENDOPT",
  51. "P2P_DEV_ADDR",
  52. "SETFWPATH",
  53. "SETBAND",
  54. "GETBAND",
  55. "COUNTRY",
  56. "P2P_SET_NOA",
  57. "P2P_GET_NOA",
  58. "P2P_SET_PS",
  59. "SET_AP_WPS_P2P_IE",
  60. "MIRACAST",
  61. #ifdef CONFIG_PNO_SUPPORT
  62. "PNOSSIDCLR",
  63. "PNOSETUP",
  64. "PNOFORCE",
  65. "PNODEBUG",
  66. #endif
  67. "MACADDR",
  68. "BLOCK_SCAN",
  69. "BLOCK",
  70. "WFD-ENABLE",
  71. "WFD-DISABLE",
  72. "WFD-SET-TCPPORT",
  73. "WFD-SET-MAXTPUT",
  74. "WFD-SET-DEVTYPE",
  75. "SET_DTIM",
  76. "HOSTAPD_SET_MACADDR_ACL",
  77. "HOSTAPD_ACL_ADD_STA",
  78. "HOSTAPD_ACL_REMOVE_STA",
  79. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0))
  80. "GTK_REKEY_OFFLOAD",
  81. #endif /* CONFIG_GTK_OL */
  82. /* Private command for P2P disable*/
  83. "P2P_DISABLE",
  84. "SET_AEK",
  85. "DRIVER_VERSION"
  86. };
  87. #ifdef CONFIG_PNO_SUPPORT
  88. #define PNO_TLV_PREFIX 'S'
  89. #define PNO_TLV_VERSION '1'
  90. #define PNO_TLV_SUBVERSION '2'
  91. #define PNO_TLV_RESERVED '0'
  92. #define PNO_TLV_TYPE_SSID_IE 'S'
  93. #define PNO_TLV_TYPE_TIME 'T'
  94. #define PNO_TLV_FREQ_REPEAT 'R'
  95. #define PNO_TLV_FREQ_EXPO_MAX 'M'
  96. typedef struct cmd_tlv {
  97. char prefix;
  98. char version;
  99. char subver;
  100. char reserved;
  101. } cmd_tlv_t;
  102. #ifdef CONFIG_PNO_SET_DEBUG
  103. char pno_in_example[] = {
  104. 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ',
  105. 'S', '1', '2', '0',
  106. 'S', /* 1 */
  107. 0x05,
  108. 'd', 'l', 'i', 'n', 'k',
  109. 'S', /* 2 */
  110. 0x06,
  111. 'B', 'U', 'F', 'B', 'U', 'F',
  112. 'S', /* 3 */
  113. 0x20,
  114. 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '@', '#', '$', '%', '^',
  115. 'S', /* 4 */
  116. 0x0a,
  117. '!', '@', '#', '$', '%', '^', '&', '*', '(', ')',
  118. 'T',
  119. '0', '5',
  120. 'R',
  121. '2',
  122. 'M',
  123. '2',
  124. 0x00
  125. };
  126. #endif /* CONFIG_PNO_SET_DEBUG */
  127. #endif /* PNO_SUPPORT */
  128. typedef struct android_wifi_priv_cmd {
  129. char *buf;
  130. int used_len;
  131. int total_len;
  132. } android_wifi_priv_cmd;
  133. #ifdef CONFIG_COMPAT
  134. typedef struct compat_android_wifi_priv_cmd {
  135. compat_uptr_t buf;
  136. int used_len;
  137. int total_len;
  138. } compat_android_wifi_priv_cmd;
  139. #endif /* CONFIG_COMPAT */
  140. /**
  141. * Local (static) functions and variables
  142. */
  143. /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
  144. * time (only) in dhd_open, subsequential wifi on will be handled by
  145. * wl_android_wifi_on
  146. */
  147. static int g_wifi_on = _TRUE;
  148. unsigned int oob_irq = 0;
  149. unsigned int oob_gpio = 0;
  150. #ifdef CONFIG_PNO_SUPPORT
  151. /*
  152. * rtw_android_pno_setup
  153. * Description:
  154. * This is used for private command.
  155. *
  156. * Parameter:
  157. * net: net_device
  158. * command: parameters from private command
  159. * total_len: the length of the command.
  160. *
  161. * */
  162. static int rtw_android_pno_setup(struct net_device *net, char *command, int total_len)
  163. {
  164. pno_ssid_t pno_ssids_local[MAX_PNO_LIST_COUNT];
  165. int res = -1;
  166. int nssid = 0;
  167. cmd_tlv_t *cmd_tlv_temp;
  168. char *str_ptr;
  169. int tlv_size_left;
  170. int pno_time = 0;
  171. int pno_repeat = 0;
  172. int pno_freq_expo_max = 0;
  173. int cmdlen = strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_PNOSETUP_SET]) + 1;
  174. #ifdef CONFIG_PNO_SET_DEBUG
  175. int i;
  176. char *p;
  177. p = pno_in_example;
  178. total_len = sizeof(pno_in_example);
  179. str_ptr = p + cmdlen;
  180. #else
  181. str_ptr = command + cmdlen;
  182. #endif
  183. if (total_len < (cmdlen + sizeof(cmd_tlv_t))) {
  184. RTW_INFO("%s argument=%d less min size\n", __func__, total_len);
  185. goto exit_proc;
  186. }
  187. tlv_size_left = total_len - cmdlen;
  188. cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
  189. memset(pno_ssids_local, 0, sizeof(pno_ssids_local));
  190. if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
  191. (cmd_tlv_temp->version == PNO_TLV_VERSION) &&
  192. (cmd_tlv_temp->subver == PNO_TLV_SUBVERSION)) {
  193. str_ptr += sizeof(cmd_tlv_t);
  194. tlv_size_left -= sizeof(cmd_tlv_t);
  195. nssid = rtw_parse_ssid_list_tlv(&str_ptr, pno_ssids_local,
  196. MAX_PNO_LIST_COUNT, &tlv_size_left);
  197. if (nssid <= 0) {
  198. RTW_INFO("SSID is not presented or corrupted ret=%d\n", nssid);
  199. goto exit_proc;
  200. } else {
  201. if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) {
  202. RTW_INFO("%s scan duration corrupted field size %d\n",
  203. __func__, tlv_size_left);
  204. goto exit_proc;
  205. }
  206. str_ptr++;
  207. pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
  208. RTW_INFO("%s: pno_time=%d\n", __func__, pno_time);
  209. if (str_ptr[0] != 0) {
  210. if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
  211. RTW_INFO("%s pno repeat : corrupted field\n",
  212. __func__);
  213. goto exit_proc;
  214. }
  215. str_ptr++;
  216. pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16);
  217. RTW_INFO("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat);
  218. if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) {
  219. RTW_INFO("%s FREQ_EXPO_MAX corrupted field size\n",
  220. __func__);
  221. goto exit_proc;
  222. }
  223. str_ptr++;
  224. pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16);
  225. RTW_INFO("%s: pno_freq_expo_max=%d\n",
  226. __func__, pno_freq_expo_max);
  227. }
  228. }
  229. } else {
  230. RTW_INFO("%s get wrong TLV command\n", __FUNCTION__);
  231. goto exit_proc;
  232. }
  233. res = rtw_dev_pno_set(net, pno_ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max);
  234. #ifdef CONFIG_PNO_SET_DEBUG
  235. rtw_dev_pno_debug(net);
  236. #endif
  237. exit_proc:
  238. return res;
  239. }
  240. /*
  241. * rtw_android_cfg80211_pno_setup
  242. * Description:
  243. * This is used for cfg80211 sched_scan.
  244. *
  245. * Parameter:
  246. * net: net_device
  247. * request: cfg80211_request
  248. * */
  249. int rtw_android_cfg80211_pno_setup(struct net_device *net,
  250. struct cfg80211_ssid *ssids, int n_ssids, int interval)
  251. {
  252. int res = -1;
  253. int nssid = 0;
  254. int pno_time = 0;
  255. int pno_repeat = 0;
  256. int pno_freq_expo_max = 0;
  257. int index = 0;
  258. pno_ssid_t pno_ssids_local[MAX_PNO_LIST_COUNT];
  259. if (n_ssids > MAX_PNO_LIST_COUNT || n_ssids < 0) {
  260. RTW_INFO("%s: nssids(%d) is invalid.\n", __func__, n_ssids);
  261. return -EINVAL;
  262. }
  263. memset(pno_ssids_local, 0, sizeof(pno_ssids_local));
  264. nssid = n_ssids;
  265. for (index = 0 ; index < nssid ; index++) {
  266. pno_ssids_local[index].SSID_len = ssids[index].ssid_len;
  267. memcpy(pno_ssids_local[index].SSID, ssids[index].ssid,
  268. ssids[index].ssid_len);
  269. }
  270. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
  271. if(ssids)
  272. rtw_mfree((u8 *)ssids, (n_ssids * sizeof(struct cfg80211_ssid)));
  273. #endif
  274. pno_time = (interval / 1000);
  275. RTW_INFO("%s: nssids: %d, pno_time=%d\n", __func__, nssid, pno_time);
  276. res = rtw_dev_pno_set(net, pno_ssids_local, nssid, pno_time,
  277. pno_repeat, pno_freq_expo_max);
  278. #ifdef CONFIG_PNO_SET_DEBUG
  279. rtw_dev_pno_debug(net);
  280. #endif
  281. exit_proc:
  282. return res;
  283. }
  284. int rtw_android_pno_enable(struct net_device *net, int pno_enable)
  285. {
  286. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  287. struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
  288. if (pwrctl) {
  289. pwrctl->wowlan_pno_enable = pno_enable;
  290. RTW_INFO("%s: wowlan_pno_enable: %d\n", __func__, pwrctl->wowlan_pno_enable);
  291. if (pwrctl->wowlan_pno_enable == 0) {
  292. if (pwrctl->pnlo_info != NULL) {
  293. rtw_mfree((u8 *)pwrctl->pnlo_info, sizeof(pno_nlo_info_t));
  294. pwrctl->pnlo_info = NULL;
  295. }
  296. if (pwrctl->pno_ssid_list != NULL) {
  297. rtw_mfree((u8 *)pwrctl->pno_ssid_list, sizeof(pno_ssid_list_t));
  298. pwrctl->pno_ssid_list = NULL;
  299. }
  300. if (pwrctl->pscan_info != NULL) {
  301. rtw_mfree((u8 *)pwrctl->pscan_info, sizeof(pno_scan_info_t));
  302. pwrctl->pscan_info = NULL;
  303. }
  304. }
  305. return 0;
  306. } else
  307. return -1;
  308. }
  309. #endif /* CONFIG_PNO_SUPPORT */
  310. int rtw_android_cmdstr_to_num(char *cmdstr)
  311. {
  312. int cmd_num;
  313. for (cmd_num = 0 ; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
  314. if (0 == strnicmp(cmdstr , android_wifi_cmd_str[cmd_num], strlen(android_wifi_cmd_str[cmd_num])))
  315. break;
  316. return cmd_num;
  317. }
  318. int rtw_android_get_rssi(struct net_device *net, char *command, int total_len)
  319. {
  320. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  321. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  322. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  323. int bytes_written = 0;
  324. if (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  325. bytes_written += snprintf(&command[bytes_written], total_len, "%s rssi %d",
  326. pcur_network->network.Ssid.Ssid, padapter->recvpriv.rssi);
  327. }
  328. return bytes_written;
  329. }
  330. int rtw_android_get_link_speed(struct net_device *net, char *command, int total_len)
  331. {
  332. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  333. int bytes_written = 0;
  334. u16 link_speed = 0;
  335. link_speed = rtw_get_cur_max_rate(padapter) / 10;
  336. bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed);
  337. return bytes_written;
  338. }
  339. int rtw_android_get_macaddr(struct net_device *net, char *command, int total_len)
  340. {
  341. int bytes_written = 0;
  342. bytes_written = snprintf(command, total_len, "Macaddr = "MAC_FMT, MAC_ARG(net->dev_addr));
  343. return bytes_written;
  344. }
  345. int rtw_android_set_country(struct net_device *net, char *command, int total_len)
  346. {
  347. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  348. char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
  349. int ret = _FAIL;
  350. ret = rtw_set_country(adapter, country_code);
  351. return (ret == _SUCCESS) ? 0 : -1;
  352. }
  353. int rtw_android_get_p2p_dev_addr(struct net_device *net, char *command, int total_len)
  354. {
  355. int bytes_written = 0;
  356. /* We use the same address as our HW MAC address */
  357. _rtw_memcpy(command, net->dev_addr, ETH_ALEN);
  358. bytes_written = ETH_ALEN;
  359. return bytes_written;
  360. }
  361. int rtw_android_set_block_scan(struct net_device *net, char *command, int total_len)
  362. {
  363. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  364. char *block_value = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_BLOCK_SCAN]) + 1;
  365. #ifdef CONFIG_IOCTL_CFG80211
  366. adapter_wdev_data(adapter)->block_scan = (*block_value == '0') ? _FALSE : _TRUE;
  367. #endif
  368. return 0;
  369. }
  370. int rtw_android_set_block(struct net_device *net, char *command, int total_len)
  371. {
  372. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  373. char *block_value = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_BLOCK]) + 1;
  374. #ifdef CONFIG_IOCTL_CFG80211
  375. adapter_wdev_data(adapter)->block = (*block_value == '0') ? _FALSE : _TRUE;
  376. #endif
  377. return 0;
  378. }
  379. int rtw_android_setband(struct net_device *net, char *command, int total_len)
  380. {
  381. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  382. char *arg = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SETBAND]) + 1;
  383. u32 band = WIFI_FREQUENCY_BAND_AUTO;
  384. int ret = _FAIL;
  385. if (sscanf(arg, "%u", &band) >= 1)
  386. ret = rtw_set_band(adapter, band);
  387. return (ret == _SUCCESS) ? 0 : -1;
  388. }
  389. int rtw_android_getband(struct net_device *net, char *command, int total_len)
  390. {
  391. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  392. int bytes_written = 0;
  393. bytes_written = snprintf(command, total_len, "%u", adapter->setband);
  394. return bytes_written;
  395. }
  396. #ifdef CONFIG_WFD
  397. int rtw_android_set_miracast_mode(struct net_device *net, char *command, int total_len)
  398. {
  399. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  400. struct wifi_display_info *wfd_info = &adapter->wfd_info;
  401. char *arg = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_MIRACAST]) + 1;
  402. u8 mode;
  403. int num;
  404. int ret = _FAIL;
  405. num = sscanf(arg, "%hhu", &mode);
  406. if (num < 1)
  407. goto exit;
  408. switch (mode) {
  409. case 1: /* soruce */
  410. mode = MIRACAST_SOURCE;
  411. break;
  412. case 2: /* sink */
  413. mode = MIRACAST_SINK;
  414. break;
  415. case 0: /* disabled */
  416. default:
  417. mode = MIRACAST_DISABLED;
  418. break;
  419. }
  420. wfd_info->stack_wfd_mode = mode;
  421. RTW_INFO("stack miracast mode: %s\n", get_miracast_mode_str(wfd_info->stack_wfd_mode));
  422. ret = _SUCCESS;
  423. exit:
  424. return (ret == _SUCCESS) ? 0 : -1;
  425. }
  426. #endif /* CONFIG_WFD */
  427. int get_int_from_command(char *pcmd)
  428. {
  429. int i = 0;
  430. for (i = 0; i < strlen(pcmd); i++) {
  431. if (pcmd[i] == '=') {
  432. /* Skip the '=' and space characters. */
  433. i += 2;
  434. break;
  435. }
  436. }
  437. return rtw_atoi(pcmd + i) ;
  438. }
  439. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0))
  440. int rtw_gtk_offload(struct net_device *net, u8 *cmd_ptr)
  441. {
  442. int i;
  443. /* u8 *cmd_ptr = priv_cmd.buf; */
  444. struct sta_info *psta;
  445. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  446. struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
  447. struct sta_priv *pstapriv = &padapter->stapriv;
  448. struct security_priv *psecuritypriv = &(padapter->securitypriv);
  449. psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
  450. if (psta == NULL)
  451. RTW_INFO("%s, : Obtain Sta_info fail\n", __func__);
  452. else {
  453. /* string command length of "GTK_REKEY_OFFLOAD" */
  454. cmd_ptr += 18;
  455. _rtw_memcpy(psta->kek, cmd_ptr, RTW_KEK_LEN);
  456. cmd_ptr += RTW_KEK_LEN;
  457. /*
  458. printk("supplicant KEK: ");
  459. for(i=0;i<RTW_KEK_LEN; i++)
  460. printk(" %02x ", psta->kek[i]);
  461. printk("\n supplicant KCK: ");
  462. */
  463. _rtw_memcpy(psta->kck, cmd_ptr, RTW_KCK_LEN);
  464. cmd_ptr += RTW_KCK_LEN;
  465. /*
  466. for(i=0;i<RTW_KEK_LEN; i++)
  467. printk(" %02x ", psta->kck[i]);
  468. */
  469. _rtw_memcpy(psta->replay_ctr, cmd_ptr, RTW_REPLAY_CTR_LEN);
  470. psecuritypriv->binstallKCK_KEK = _TRUE;
  471. /* printk("\nREPLAY_CTR: "); */
  472. /* for(i=0;i<RTW_REPLAY_CTR_LEN; i++) */
  473. /* printk(" %02x ", psta->replay_ctr[i]); */
  474. }
  475. return _SUCCESS;
  476. }
  477. #endif /* CONFIG_GTK_OL */
  478. #ifdef CONFIG_RTW_MESH_AEK
  479. static int rtw_android_set_aek(struct net_device *ndev, char *command, int total_len)
  480. {
  481. #define SET_AEK_DATA_LEN (ETH_ALEN + 32)
  482. _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);
  483. u8 *addr;
  484. u8 *aek;
  485. int err = 0;
  486. if (total_len - strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SET_AEK]) - 1 != SET_AEK_DATA_LEN) {
  487. err = -EINVAL;
  488. goto exit;
  489. }
  490. addr = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SET_AEK]) + 1;
  491. aek = addr + ETH_ALEN;
  492. RTW_PRINT(FUNC_NDEV_FMT" addr="MAC_FMT"\n"
  493. , FUNC_NDEV_ARG(ndev), MAC_ARG(addr));
  494. if (0)
  495. RTW_PRINT(FUNC_NDEV_FMT" aek="KEY_FMT KEY_FMT"\n"
  496. , FUNC_NDEV_ARG(ndev), KEY_ARG(aek), KEY_ARG(aek + 16));
  497. if (rtw_mesh_plink_set_aek(adapter, addr, aek) != _SUCCESS)
  498. err = -ENOENT;
  499. exit:
  500. return err;
  501. }
  502. #endif /* CONFIG_RTW_MESH_AEK */
  503. int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
  504. {
  505. #define PRIVATE_COMMAND_MAX_LEN 8192
  506. int ret = 0;
  507. char *command = NULL;
  508. int cmd_num;
  509. int bytes_written = 0;
  510. #ifdef CONFIG_PNO_SUPPORT
  511. uint cmdlen = 0;
  512. uint pno_enable = 0;
  513. #endif
  514. android_wifi_priv_cmd priv_cmd;
  515. _adapter *padapter = (_adapter *) rtw_netdev_priv(net);
  516. #ifdef CONFIG_WFD
  517. struct wifi_display_info *pwfd_info;
  518. #endif
  519. rtw_lock_suspend();
  520. if (!ifr->ifr_data) {
  521. ret = -EINVAL;
  522. goto exit;
  523. }
  524. if (padapter->registrypriv.mp_mode == 1) {
  525. ret = -EINVAL;
  526. goto exit;
  527. }
  528. #ifdef CONFIG_COMPAT
  529. #if (KERNEL_VERSION(4, 6, 0) > LINUX_VERSION_CODE)
  530. if (is_compat_task()) {
  531. #else
  532. if (in_compat_syscall()) {
  533. #endif
  534. /* User space is 32-bit, use compat ioctl */
  535. compat_android_wifi_priv_cmd compat_priv_cmd;
  536. if (copy_from_user(&compat_priv_cmd, ifr->ifr_data, sizeof(compat_android_wifi_priv_cmd))) {
  537. ret = -EFAULT;
  538. goto exit;
  539. }
  540. priv_cmd.buf = compat_ptr(compat_priv_cmd.buf);
  541. priv_cmd.used_len = compat_priv_cmd.used_len;
  542. priv_cmd.total_len = compat_priv_cmd.total_len;
  543. } else
  544. #endif /* CONFIG_COMPAT */
  545. if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) {
  546. ret = -EFAULT;
  547. goto exit;
  548. }
  549. if (padapter->registrypriv.mp_mode == 1) {
  550. ret = -EFAULT;
  551. goto exit;
  552. }
  553. /*RTW_INFO("%s priv_cmd.buf=%p priv_cmd.total_len=%d priv_cmd.used_len=%d\n",__func__,priv_cmd.buf,priv_cmd.total_len,priv_cmd.used_len);*/
  554. if (priv_cmd.total_len > PRIVATE_COMMAND_MAX_LEN || priv_cmd.total_len < 0) {
  555. RTW_WARN("%s: invalid private command (%d)\n", __FUNCTION__,
  556. priv_cmd.total_len);
  557. ret = -EFAULT;
  558. goto exit;
  559. }
  560. command = rtw_zmalloc(priv_cmd.total_len+1);
  561. if (!command) {
  562. RTW_INFO("%s: failed to allocate memory\n", __FUNCTION__);
  563. ret = -ENOMEM;
  564. goto exit;
  565. }
  566. if (!access_ok(priv_cmd.buf, priv_cmd.total_len)) {
  567. RTW_INFO("%s: failed to access memory\n", __FUNCTION__);
  568. ret = -EFAULT;
  569. goto exit;
  570. }
  571. if (copy_from_user(command, (void *)priv_cmd.buf, priv_cmd.total_len)) {
  572. ret = -EFAULT;
  573. goto exit;
  574. }
  575. command[priv_cmd.total_len] = '\0';
  576. RTW_INFO("%s: Android private cmd \"%s\" on %s\n"
  577. , __FUNCTION__, command, ifr->ifr_name);
  578. cmd_num = rtw_android_cmdstr_to_num(command);
  579. switch (cmd_num) {
  580. case ANDROID_WIFI_CMD_START:
  581. /* bytes_written = wl_android_wifi_on(net); */
  582. goto response;
  583. case ANDROID_WIFI_CMD_SETFWPATH:
  584. goto response;
  585. }
  586. if (!g_wifi_on) {
  587. RTW_INFO("%s: Ignore private cmd \"%s\" - iface %s is down\n"
  588. , __FUNCTION__, command, ifr->ifr_name);
  589. ret = 0;
  590. goto exit;
  591. }
  592. if (!hal_chk_wl_func(padapter, WL_FUNC_MIRACAST)) {
  593. switch (cmd_num) {
  594. case ANDROID_WIFI_CMD_WFD_ENABLE:
  595. case ANDROID_WIFI_CMD_WFD_DISABLE:
  596. case ANDROID_WIFI_CMD_WFD_SET_TCPPORT:
  597. case ANDROID_WIFI_CMD_WFD_SET_MAX_TPUT:
  598. case ANDROID_WIFI_CMD_WFD_SET_DEVTYPE:
  599. goto response;
  600. }
  601. }
  602. switch (cmd_num) {
  603. case ANDROID_WIFI_CMD_STOP:
  604. /* bytes_written = wl_android_wifi_off(net); */
  605. break;
  606. case ANDROID_WIFI_CMD_SCAN_ACTIVE:
  607. /* rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_ACTIVE); */
  608. #ifdef CONFIG_PLATFORM_MSTAR
  609. #ifdef CONFIG_IOCTL_CFG80211
  610. adapter_wdev_data((_adapter *)rtw_netdev_priv(net))->bandroid_scan = _TRUE;
  611. #endif /* CONFIG_IOCTL_CFG80211 */
  612. #endif /* CONFIG_PLATFORM_MSTAR */
  613. break;
  614. case ANDROID_WIFI_CMD_SCAN_PASSIVE:
  615. /* rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_PASSIVE); */
  616. break;
  617. case ANDROID_WIFI_CMD_RSSI:
  618. bytes_written = rtw_android_get_rssi(net, command, priv_cmd.total_len);
  619. break;
  620. case ANDROID_WIFI_CMD_LINKSPEED:
  621. bytes_written = rtw_android_get_link_speed(net, command, priv_cmd.total_len);
  622. break;
  623. case ANDROID_WIFI_CMD_MACADDR:
  624. bytes_written = rtw_android_get_macaddr(net, command, priv_cmd.total_len);
  625. break;
  626. case ANDROID_WIFI_CMD_BLOCK_SCAN:
  627. bytes_written = rtw_android_set_block_scan(net, command, priv_cmd.total_len);
  628. break;
  629. case ANDROID_WIFI_CMD_BLOCK:
  630. bytes_written = rtw_android_set_block(net, command, priv_cmd.total_len);
  631. break;
  632. case ANDROID_WIFI_CMD_RXFILTER_START:
  633. /* bytes_written = net_os_set_packet_filter(net, 1); */
  634. break;
  635. case ANDROID_WIFI_CMD_RXFILTER_STOP:
  636. /* bytes_written = net_os_set_packet_filter(net, 0); */
  637. break;
  638. case ANDROID_WIFI_CMD_RXFILTER_ADD:
  639. /* int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0'; */
  640. /* bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num); */
  641. break;
  642. case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
  643. /* int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0'; */
  644. /* bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num); */
  645. break;
  646. case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
  647. /* TBD: BTCOEXSCAN-START */
  648. break;
  649. case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
  650. /* TBD: BTCOEXSCAN-STOP */
  651. break;
  652. case ANDROID_WIFI_CMD_BTCOEXMODE:
  653. #if 0
  654. uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
  655. if (mode == 1)
  656. net_os_set_packet_filter(net, 0); /* DHCP starts */
  657. else
  658. net_os_set_packet_filter(net, 1); /* DHCP ends */
  659. #ifdef WL_CFG80211
  660. bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command);
  661. #endif
  662. #endif
  663. break;
  664. case ANDROID_WIFI_CMD_SETSUSPENDOPT:
  665. /* bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len); */
  666. break;
  667. case ANDROID_WIFI_CMD_SETBAND:
  668. bytes_written = rtw_android_setband(net, command, priv_cmd.total_len);
  669. break;
  670. case ANDROID_WIFI_CMD_GETBAND:
  671. bytes_written = rtw_android_getband(net, command, priv_cmd.total_len);
  672. break;
  673. case ANDROID_WIFI_CMD_COUNTRY:
  674. bytes_written = rtw_android_set_country(net, command, priv_cmd.total_len);
  675. break;
  676. #ifdef CONFIG_PNO_SUPPORT
  677. case ANDROID_WIFI_CMD_PNOSSIDCLR_SET:
  678. /* bytes_written = dhd_dev_pno_reset(net); */
  679. break;
  680. case ANDROID_WIFI_CMD_PNOSETUP_SET:
  681. bytes_written = rtw_android_pno_setup(net, command, priv_cmd.total_len);
  682. break;
  683. case ANDROID_WIFI_CMD_PNOENABLE_SET:
  684. cmdlen = strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_PNOENABLE_SET]);
  685. pno_enable = *(command + cmdlen + 1) - '0';
  686. bytes_written = rtw_android_pno_enable(net, pno_enable);
  687. break;
  688. #endif
  689. case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
  690. bytes_written = rtw_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
  691. break;
  692. case ANDROID_WIFI_CMD_P2P_SET_NOA:
  693. /* int skip = strlen(CMD_P2P_SET_NOA) + 1; */
  694. /* bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip, priv_cmd.total_len - skip); */
  695. break;
  696. case ANDROID_WIFI_CMD_P2P_GET_NOA:
  697. /* bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len); */
  698. break;
  699. case ANDROID_WIFI_CMD_P2P_SET_PS:
  700. /* int skip = strlen(CMD_P2P_SET_PS) + 1; */
  701. /* bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip, priv_cmd.total_len - skip); */
  702. break;
  703. #ifdef CONFIG_IOCTL_CFG80211
  704. case ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE: {
  705. int skip = strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE]) + 3;
  706. bytes_written = rtw_cfg80211_set_mgnt_wpsp2pie(net, command + skip, priv_cmd.total_len - skip, *(command + skip - 2) - '0');
  707. break;
  708. }
  709. #endif /* CONFIG_IOCTL_CFG80211 */
  710. #ifdef CONFIG_WFD
  711. case ANDROID_WIFI_CMD_MIRACAST:
  712. bytes_written = rtw_android_set_miracast_mode(net, command, priv_cmd.total_len);
  713. break;
  714. case ANDROID_WIFI_CMD_WFD_ENABLE: {
  715. /* Commented by Albert 2012/07/24 */
  716. /* We can enable the WFD function by using the following command: */
  717. /* wpa_cli driver wfd-enable */
  718. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211)
  719. rtw_wfd_enable(padapter, 1);
  720. break;
  721. }
  722. case ANDROID_WIFI_CMD_WFD_DISABLE: {
  723. /* Commented by Albert 2012/07/24 */
  724. /* We can disable the WFD function by using the following command: */
  725. /* wpa_cli driver wfd-disable */
  726. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211)
  727. rtw_wfd_enable(padapter, 0);
  728. break;
  729. }
  730. case ANDROID_WIFI_CMD_WFD_SET_TCPPORT: {
  731. /* Commented by Albert 2012/07/24 */
  732. /* We can set the tcp port number by using the following command: */
  733. /* wpa_cli driver wfd-set-tcpport = 554 */
  734. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211)
  735. rtw_wfd_set_ctrl_port(padapter, (u16)get_int_from_command(command));
  736. break;
  737. }
  738. case ANDROID_WIFI_CMD_WFD_SET_MAX_TPUT: {
  739. break;
  740. }
  741. case ANDROID_WIFI_CMD_WFD_SET_DEVTYPE: {
  742. /* Commented by Albert 2012/08/28 */
  743. /* Specify the WFD device type ( WFD source/primary sink ) */
  744. pwfd_info = &padapter->wfd_info;
  745. if (padapter->wdinfo.driver_interface == DRIVER_CFG80211) {
  746. pwfd_info->wfd_device_type = (u8) get_int_from_command(command);
  747. pwfd_info->wfd_device_type &= WFD_DEVINFO_DUAL;
  748. }
  749. break;
  750. }
  751. #endif
  752. case ANDROID_WIFI_CMD_CHANGE_DTIM: {
  753. #ifdef CONFIG_LPS
  754. u8 dtim;
  755. u8 *ptr = (u8 *) command;
  756. ptr += 9;/* string command length of "SET_DTIM"; */
  757. dtim = rtw_atoi(ptr);
  758. RTW_INFO("DTIM=%d\n", dtim);
  759. rtw_lps_change_dtim_cmd(padapter, dtim);
  760. #endif
  761. }
  762. break;
  763. #if CONFIG_RTW_MACADDR_ACL
  764. case ANDROID_WIFI_CMD_HOSTAPD_SET_MACADDR_ACL: {
  765. rtw_set_macaddr_acl(padapter, RTW_ACL_PERIOD_BSS, get_int_from_command(command));
  766. break;
  767. }
  768. case ANDROID_WIFI_CMD_HOSTAPD_ACL_ADD_STA: {
  769. u8 addr[ETH_ALEN] = {0x00};
  770. macstr2num(addr, command + strlen("HOSTAPD_ACL_ADD_STA") + 3); /* 3 is space bar + "=" + space bar these 3 chars */
  771. rtw_acl_add_sta(padapter, RTW_ACL_PERIOD_BSS, addr);
  772. break;
  773. }
  774. case ANDROID_WIFI_CMD_HOSTAPD_ACL_REMOVE_STA: {
  775. u8 addr[ETH_ALEN] = {0x00};
  776. macstr2num(addr, command + strlen("HOSTAPD_ACL_REMOVE_STA") + 3); /* 3 is space bar + "=" + space bar these 3 chars */
  777. rtw_acl_remove_sta(padapter, RTW_ACL_PERIOD_BSS, addr);
  778. break;
  779. }
  780. #endif /* CONFIG_RTW_MACADDR_ACL */
  781. #if defined(CONFIG_GTK_OL) && (LINUX_VERSION_CODE < KERNEL_VERSION(3, 1, 0))
  782. case ANDROID_WIFI_CMD_GTK_REKEY_OFFLOAD:
  783. rtw_gtk_offload(net, (u8 *)command);
  784. break;
  785. #endif /* CONFIG_GTK_OL */
  786. case ANDROID_WIFI_CMD_P2P_DISABLE: {
  787. #ifdef CONFIG_P2P
  788. rtw_p2p_enable(padapter, P2P_ROLE_DISABLE);
  789. #endif /* CONFIG_P2P */
  790. break;
  791. }
  792. #ifdef CONFIG_RTW_MESH_AEK
  793. case ANDROID_WIFI_CMD_SET_AEK:
  794. bytes_written = rtw_android_set_aek(net, command, priv_cmd.total_len);
  795. break;
  796. #endif
  797. case ANDROID_WIFI_CMD_DRIVERVERSION: {
  798. bytes_written = strlen(DRIVERVERSION);
  799. snprintf(command, bytes_written + 1, DRIVERVERSION);
  800. break;
  801. }
  802. default:
  803. RTW_INFO("Unknown PRIVATE command %s - ignored\n", command);
  804. snprintf(command, 3, "OK");
  805. bytes_written = strlen("OK");
  806. }
  807. response:
  808. if (bytes_written >= 0) {
  809. if ((bytes_written == 0) && (priv_cmd.total_len > 0))
  810. command[0] = '\0';
  811. if (bytes_written >= priv_cmd.total_len) {
  812. RTW_INFO("%s: bytes_written = %d\n", __FUNCTION__, bytes_written);
  813. bytes_written = priv_cmd.total_len;
  814. } else
  815. bytes_written++;
  816. priv_cmd.used_len = bytes_written;
  817. if (copy_to_user((void *)priv_cmd.buf, command, bytes_written)) {
  818. RTW_INFO("%s: failed to copy data to user buffer\n", __FUNCTION__);
  819. ret = -EFAULT;
  820. }
  821. } else
  822. ret = bytes_written;
  823. exit:
  824. rtw_unlock_suspend();
  825. if (command)
  826. rtw_mfree(command, priv_cmd.total_len);
  827. return ret;
  828. }
  829. /**
  830. * Functions for Android WiFi card detection
  831. */
  832. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  833. static int g_wifidev_registered = 0;
  834. static struct semaphore wifi_control_sem;
  835. static struct wifi_platform_data *wifi_control_data = NULL;
  836. static struct resource *wifi_irqres = NULL;
  837. static int wifi_add_dev(void);
  838. static void wifi_del_dev(void);
  839. int rtw_android_wifictrl_func_add(void)
  840. {
  841. int ret = 0;
  842. sema_init(&wifi_control_sem, 0);
  843. ret = wifi_add_dev();
  844. if (ret) {
  845. RTW_INFO("%s: platform_driver_register failed\n", __FUNCTION__);
  846. return ret;
  847. }
  848. g_wifidev_registered = 1;
  849. /* Waiting callback after platform_driver_register is done or exit with error */
  850. if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
  851. ret = -EINVAL;
  852. RTW_INFO("%s: platform_driver_register timeout\n", __FUNCTION__);
  853. }
  854. return ret;
  855. }
  856. void rtw_android_wifictrl_func_del(void)
  857. {
  858. if (g_wifidev_registered) {
  859. wifi_del_dev();
  860. g_wifidev_registered = 0;
  861. }
  862. }
  863. void *wl_android_prealloc(int section, unsigned long size)
  864. {
  865. void *alloc_ptr = NULL;
  866. if (wifi_control_data && wifi_control_data->mem_prealloc) {
  867. alloc_ptr = wifi_control_data->mem_prealloc(section, size);
  868. if (alloc_ptr) {
  869. RTW_INFO("success alloc section %d\n", section);
  870. if (size != 0L)
  871. memset(alloc_ptr, 0, size);
  872. return alloc_ptr;
  873. }
  874. }
  875. RTW_INFO("can't alloc section %d\n", section);
  876. return NULL;
  877. }
  878. int wifi_get_irq_number(unsigned long *irq_flags_ptr)
  879. {
  880. if (wifi_irqres) {
  881. *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
  882. return (int)wifi_irqres->start;
  883. }
  884. #ifdef CUSTOM_OOB_GPIO_NUM
  885. return CUSTOM_OOB_GPIO_NUM;
  886. #else
  887. return -1;
  888. #endif
  889. }
  890. int wifi_set_power(int on, unsigned long msec)
  891. {
  892. RTW_INFO("%s = %d\n", __FUNCTION__, on);
  893. if (wifi_control_data && wifi_control_data->set_power)
  894. wifi_control_data->set_power(on);
  895. if (msec)
  896. msleep(msec);
  897. return 0;
  898. }
  899. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  900. int wifi_get_mac_addr(unsigned char *buf)
  901. {
  902. RTW_INFO("%s\n", __FUNCTION__);
  903. if (!buf)
  904. return -EINVAL;
  905. if (wifi_control_data && wifi_control_data->get_mac_addr)
  906. return wifi_control_data->get_mac_addr(buf);
  907. return -EOPNOTSUPP;
  908. }
  909. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
  910. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) || defined(COMPAT_KERNEL_RELEASE)
  911. void *wifi_get_country_code(char *ccode)
  912. {
  913. RTW_INFO("%s\n", __FUNCTION__);
  914. if (!ccode)
  915. return NULL;
  916. if (wifi_control_data && wifi_control_data->get_country_code)
  917. return wifi_control_data->get_country_code(ccode);
  918. return NULL;
  919. }
  920. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
  921. static int wifi_set_carddetect(int on)
  922. {
  923. RTW_INFO("%s = %d\n", __FUNCTION__, on);
  924. if (wifi_control_data && wifi_control_data->set_carddetect)
  925. wifi_control_data->set_carddetect(on);
  926. return 0;
  927. }
  928. static int wifi_probe(struct platform_device *pdev)
  929. {
  930. struct wifi_platform_data *wifi_ctrl =
  931. (struct wifi_platform_data *)(pdev->dev.platform_data);
  932. int wifi_wake_gpio = 0;
  933. RTW_INFO("## %s\n", __FUNCTION__);
  934. wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
  935. if (wifi_irqres == NULL)
  936. wifi_irqres = platform_get_resource_byname(pdev,
  937. IORESOURCE_IRQ, "bcm4329_wlan_irq");
  938. else
  939. wifi_wake_gpio = wifi_irqres->start;
  940. #ifdef CONFIG_GPIO_WAKEUP
  941. RTW_INFO("%s: gpio:%d wifi_wake_gpio:%d\n", __func__,
  942. (int)wifi_irqres->start, wifi_wake_gpio);
  943. if (wifi_wake_gpio > 0) {
  944. #ifdef CONFIG_PLATFORM_INTEL_BYT
  945. wifi_configure_gpio();
  946. #else /* CONFIG_PLATFORM_INTEL_BYT */
  947. gpio_request(wifi_wake_gpio, "oob_irq");
  948. gpio_direction_input(wifi_wake_gpio);
  949. oob_irq = gpio_to_irq(wifi_wake_gpio);
  950. #endif /* CONFIG_PLATFORM_INTEL_BYT */
  951. RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq);
  952. } else if (wifi_irqres) {
  953. oob_irq = wifi_irqres->start;
  954. RTW_INFO("%s oob_irq:%d\n", __func__, oob_irq);
  955. }
  956. #endif
  957. wifi_control_data = wifi_ctrl;
  958. wifi_set_power(1, 0); /* Power On */
  959. wifi_set_carddetect(1); /* CardDetect (0->1) */
  960. up(&wifi_control_sem);
  961. return 0;
  962. }
  963. #ifdef RTW_SUPPORT_PLATFORM_SHUTDOWN
  964. extern PADAPTER g_test_adapter;
  965. static void shutdown_card(void)
  966. {
  967. u32 addr;
  968. u8 tmp8, cnt = 0;
  969. if (NULL == g_test_adapter) {
  970. RTW_INFO("%s: padapter==NULL\n", __FUNCTION__);
  971. return;
  972. }
  973. #ifdef CONFIG_FWLPS_IN_IPS
  974. LeaveAllPowerSaveMode(g_test_adapter);
  975. #endif /* CONFIG_FWLPS_IN_IPS */
  976. #ifdef CONFIG_WOWLAN
  977. #ifdef CONFIG_GPIO_WAKEUP
  978. /*default wake up pin change to BT*/
  979. RTW_INFO("%s:default wake up pin change to BT\n", __FUNCTION__);
  980. rtw_hal_switch_gpio_wl_ctrl(g_test_adapter, WAKEUP_GPIO_IDX, _FALSE);
  981. #endif /* CONFIG_GPIO_WAKEUP */
  982. #endif /* CONFIG_WOWLAN */
  983. /* Leave SDIO HCI Suspend */
  984. addr = 0x10250086;
  985. rtw_write8(g_test_adapter, addr, 0);
  986. do {
  987. tmp8 = rtw_read8(g_test_adapter, addr);
  988. cnt++;
  989. RTW_INFO(FUNC_ADPT_FMT ": polling SDIO_HSUS_CTRL(0x%x)=0x%x, cnt=%d\n",
  990. FUNC_ADPT_ARG(g_test_adapter), addr, tmp8, cnt);
  991. if (tmp8 & BIT(1))
  992. break;
  993. if (cnt >= 100) {
  994. RTW_INFO(FUNC_ADPT_FMT ": polling 0x%x[1]==1 FAIL!!\n",
  995. FUNC_ADPT_ARG(g_test_adapter), addr);
  996. break;
  997. }
  998. rtw_mdelay_os(10);
  999. } while (1);
  1000. /* unlock register I/O */
  1001. rtw_write8(g_test_adapter, 0x1C, 0);
  1002. /* enable power down function */
  1003. /* 0x04[4] = 1 */
  1004. /* 0x05[7] = 1 */
  1005. addr = 0x04;
  1006. tmp8 = rtw_read8(g_test_adapter, addr);
  1007. tmp8 |= BIT(4);
  1008. rtw_write8(g_test_adapter, addr, tmp8);
  1009. RTW_INFO(FUNC_ADPT_FMT ": read after write 0x%x=0x%x\n",
  1010. FUNC_ADPT_ARG(g_test_adapter), addr, rtw_read8(g_test_adapter, addr));
  1011. addr = 0x05;
  1012. tmp8 = rtw_read8(g_test_adapter, addr);
  1013. tmp8 |= BIT(7);
  1014. rtw_write8(g_test_adapter, addr, tmp8);
  1015. RTW_INFO(FUNC_ADPT_FMT ": read after write 0x%x=0x%x\n",
  1016. FUNC_ADPT_ARG(g_test_adapter), addr, rtw_read8(g_test_adapter, addr));
  1017. /* lock register page0 0x0~0xB read/write */
  1018. rtw_write8(g_test_adapter, 0x1C, 0x0E);
  1019. rtw_set_surprise_removed(g_test_adapter);
  1020. RTW_INFO(FUNC_ADPT_FMT ": bSurpriseRemoved=%s\n",
  1021. FUNC_ADPT_ARG(g_test_adapter), rtw_is_surprise_removed(g_test_adapter) ? "True" : "False");
  1022. }
  1023. #endif /* RTW_SUPPORT_PLATFORM_SHUTDOWN */
  1024. static int wifi_remove(struct platform_device *pdev)
  1025. {
  1026. struct wifi_platform_data *wifi_ctrl =
  1027. (struct wifi_platform_data *)(pdev->dev.platform_data);
  1028. RTW_INFO("## %s\n", __FUNCTION__);
  1029. wifi_control_data = wifi_ctrl;
  1030. wifi_set_power(0, 0); /* Power Off */
  1031. wifi_set_carddetect(0); /* CardDetect (1->0) */
  1032. up(&wifi_control_sem);
  1033. return 0;
  1034. }
  1035. #ifdef RTW_SUPPORT_PLATFORM_SHUTDOWN
  1036. static void wifi_shutdown(struct platform_device *pdev)
  1037. {
  1038. struct wifi_platform_data *wifi_ctrl =
  1039. (struct wifi_platform_data *)(pdev->dev.platform_data);
  1040. RTW_INFO("## %s\n", __FUNCTION__);
  1041. wifi_control_data = wifi_ctrl;
  1042. shutdown_card();
  1043. wifi_set_power(0, 0); /* Power Off */
  1044. wifi_set_carddetect(0); /* CardDetect (1->0) */
  1045. }
  1046. #endif /* RTW_SUPPORT_PLATFORM_SHUTDOWN */
  1047. static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
  1048. {
  1049. RTW_INFO("##> %s\n", __FUNCTION__);
  1050. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  1051. bcmsdh_oob_intr_set(0);
  1052. #endif
  1053. return 0;
  1054. }
  1055. static int wifi_resume(struct platform_device *pdev)
  1056. {
  1057. RTW_INFO("##> %s\n", __FUNCTION__);
  1058. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  1059. if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
  1060. bcmsdh_oob_intr_set(1);
  1061. #endif
  1062. return 0;
  1063. }
  1064. /* temporarily use these two */
  1065. static struct platform_driver wifi_device = {
  1066. .probe = wifi_probe,
  1067. .remove = wifi_remove,
  1068. .suspend = wifi_suspend,
  1069. .resume = wifi_resume,
  1070. #ifdef RTW_SUPPORT_PLATFORM_SHUTDOWN
  1071. .shutdown = wifi_shutdown,
  1072. #endif /* RTW_SUPPORT_PLATFORM_SHUTDOWN */
  1073. .driver = {
  1074. .name = "bcmdhd_wlan",
  1075. }
  1076. };
  1077. static struct platform_driver wifi_device_legacy = {
  1078. .probe = wifi_probe,
  1079. .remove = wifi_remove,
  1080. .suspend = wifi_suspend,
  1081. .resume = wifi_resume,
  1082. .driver = {
  1083. .name = "bcm4329_wlan",
  1084. }
  1085. };
  1086. static int wifi_add_dev(void)
  1087. {
  1088. RTW_INFO("## Calling platform_driver_register\n");
  1089. platform_driver_register(&wifi_device);
  1090. platform_driver_register(&wifi_device_legacy);
  1091. return 0;
  1092. }
  1093. static void wifi_del_dev(void)
  1094. {
  1095. RTW_INFO("## Unregister platform_driver_register\n");
  1096. platform_driver_unregister(&wifi_device);
  1097. platform_driver_unregister(&wifi_device_legacy);
  1098. }
  1099. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */
  1100. #ifdef CONFIG_GPIO_WAKEUP
  1101. #ifdef CONFIG_PLATFORM_INTEL_BYT
  1102. int wifi_configure_gpio(void)
  1103. {
  1104. if (gpio_request(oob_gpio, "oob_irq")) {
  1105. RTW_INFO("## %s Cannot request GPIO\n", __FUNCTION__);
  1106. return -1;
  1107. }
  1108. gpio_export(oob_gpio, 0);
  1109. if (gpio_direction_input(oob_gpio)) {
  1110. RTW_INFO("## %s Cannot set GPIO direction input\n", __FUNCTION__);
  1111. return -1;
  1112. }
  1113. oob_irq = gpio_to_irq(oob_gpio);
  1114. if (oob_irq < 0) {
  1115. RTW_INFO("## %s Cannot convert GPIO to IRQ\n", __FUNCTION__);
  1116. return -1;
  1117. }
  1118. RTW_INFO("## %s OOB_IRQ=%d\n", __FUNCTION__, oob_irq);
  1119. return 0;
  1120. }
  1121. #endif /* CONFIG_PLATFORM_INTEL_BYT */
  1122. void wifi_free_gpio(unsigned int gpio)
  1123. {
  1124. #ifdef CONFIG_PLATFORM_INTEL_BYT
  1125. if (gpio)
  1126. gpio_free(gpio);
  1127. #endif /* CONFIG_PLATFORM_INTEL_BYT */
  1128. }
  1129. #endif /* CONFIG_GPIO_WAKEUP */