rtw_android.c 33 KB

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