rtw_android.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  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. #include <drv_types.h>
  21. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  22. #include <linux/platform_device.h>
  23. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  24. #include <linux/wlan_plat.h>
  25. #else
  26. #include <linux/wifi_tiwlan.h>
  27. #endif
  28. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */
  29. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
  30. #define strnicmp strncasecmp
  31. #endif
  32. const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
  33. "START",
  34. "STOP",
  35. "SCAN-ACTIVE",
  36. "SCAN-PASSIVE",
  37. "RSSI",
  38. "LINKSPEED",
  39. "RXFILTER-START",
  40. "RXFILTER-STOP",
  41. "RXFILTER-ADD",
  42. "RXFILTER-REMOVE",
  43. "BTCOEXSCAN-START",
  44. "BTCOEXSCAN-STOP",
  45. "BTCOEXMODE",
  46. "SETSUSPENDOPT",
  47. "P2P_DEV_ADDR",
  48. "SETFWPATH",
  49. "SETBAND",
  50. "GETBAND",
  51. "COUNTRY",
  52. "P2P_SET_NOA",
  53. "P2P_GET_NOA",
  54. "P2P_SET_PS",
  55. "SET_AP_WPS_P2P_IE",
  56. #ifdef PNO_SUPPORT
  57. "PNOSSIDCLR",
  58. "PNOSETUP ",
  59. "PNOFORCE",
  60. "PNODEBUG",
  61. #endif
  62. "MACADDR",
  63. "BLOCK",
  64. "WFD-ENABLE",
  65. "WFD-DISABLE",
  66. "WFD-SET-TCPPORT",
  67. "WFD-SET-MAXTPUT",
  68. "WFD-SET-DEVTYPE",
  69. };
  70. #ifdef PNO_SUPPORT
  71. #define PNO_TLV_PREFIX 'S'
  72. #define PNO_TLV_VERSION '1'
  73. #define PNO_TLV_SUBVERSION '2'
  74. #define PNO_TLV_RESERVED '0'
  75. #define PNO_TLV_TYPE_SSID_IE 'S'
  76. #define PNO_TLV_TYPE_TIME 'T'
  77. #define PNO_TLV_FREQ_REPEAT 'R'
  78. #define PNO_TLV_FREQ_EXPO_MAX 'M'
  79. typedef struct cmd_tlv {
  80. char prefix;
  81. char version;
  82. char subver;
  83. char reserved;
  84. } cmd_tlv_t;
  85. #endif /* PNO_SUPPORT */
  86. typedef struct android_wifi_priv_cmd {
  87. #ifdef CONFIG_COMPAT
  88. compat_uptr_t buf;
  89. #else
  90. char *buf;
  91. #endif
  92. int used_len;
  93. int total_len;
  94. } android_wifi_priv_cmd;
  95. /**
  96. * Local (static) functions and variables
  97. */
  98. /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
  99. * time (only) in dhd_open, subsequential wifi on will be handled by
  100. * wl_android_wifi_on
  101. */
  102. static int g_wifi_on = _TRUE;
  103. #ifdef PNO_SUPPORT
  104. static int wl_android_set_pno_setup(struct net_device *dev, char *command, int total_len)
  105. {
  106. wlc_ssid_t ssids_local[MAX_PFN_LIST_COUNT];
  107. int res = -1;
  108. int nssid = 0;
  109. cmd_tlv_t *cmd_tlv_temp;
  110. char *str_ptr;
  111. int tlv_size_left;
  112. int pno_time = 0;
  113. int pno_repeat = 0;
  114. int pno_freq_expo_max = 0;
  115. #ifdef PNO_SET_DEBUG
  116. int i;
  117. char pno_in_example[] = {
  118. 'P', 'N', 'O', 'S', 'E', 'T', 'U', 'P', ' ',
  119. 'S', '1', '2', '0',
  120. 'S',
  121. 0x05,
  122. 'd', 'l', 'i', 'n', 'k',
  123. 'S',
  124. 0x04,
  125. 'G', 'O', 'O', 'G',
  126. 'T',
  127. '0', 'B',
  128. 'R',
  129. '2',
  130. 'M',
  131. '2',
  132. 0x00
  133. };
  134. #endif /* PNO_SET_DEBUG */
  135. DHD_INFO(("%s: command=%s, len=%d\n", __FUNCTION__, command, total_len));
  136. if (total_len < (strlen(CMD_PNOSETUP_SET) + sizeof(cmd_tlv_t))) {
  137. DBG_871X("%s argument=%d less min size\n", __FUNCTION__, total_len);
  138. goto exit_proc;
  139. }
  140. #ifdef PNO_SET_DEBUG
  141. memcpy(command, pno_in_example, sizeof(pno_in_example));
  142. for (i = 0; i < sizeof(pno_in_example); i++)
  143. printf("%02X ", command[i]);
  144. printf("\n");
  145. total_len = sizeof(pno_in_example);
  146. #endif
  147. str_ptr = command + strlen(CMD_PNOSETUP_SET);
  148. tlv_size_left = total_len - strlen(CMD_PNOSETUP_SET);
  149. cmd_tlv_temp = (cmd_tlv_t *)str_ptr;
  150. memset(ssids_local, 0, sizeof(ssids_local));
  151. if ((cmd_tlv_temp->prefix == PNO_TLV_PREFIX) &&
  152. (cmd_tlv_temp->version == PNO_TLV_VERSION) &&
  153. (cmd_tlv_temp->subver == PNO_TLV_SUBVERSION)) {
  154. str_ptr += sizeof(cmd_tlv_t);
  155. tlv_size_left -= sizeof(cmd_tlv_t);
  156. if ((nssid = wl_iw_parse_ssid_list_tlv(&str_ptr, ssids_local,
  157. MAX_PFN_LIST_COUNT, &tlv_size_left)) <= 0) {
  158. DBG_871X("SSID is not presented or corrupted ret=%d\n", nssid);
  159. goto exit_proc;
  160. } else {
  161. if ((str_ptr[0] != PNO_TLV_TYPE_TIME) || (tlv_size_left <= 1)) {
  162. DBG_871X("%s scan duration corrupted field size %d\n",
  163. __FUNCTION__, tlv_size_left);
  164. goto exit_proc;
  165. }
  166. str_ptr++;
  167. pno_time = simple_strtoul(str_ptr, &str_ptr, 16);
  168. DHD_INFO(("%s: pno_time=%d\n", __FUNCTION__, pno_time));
  169. if (str_ptr[0] != 0) {
  170. if ((str_ptr[0] != PNO_TLV_FREQ_REPEAT)) {
  171. DBG_871X("%s pno repeat : corrupted field\n",
  172. __FUNCTION__);
  173. goto exit_proc;
  174. }
  175. str_ptr++;
  176. pno_repeat = simple_strtoul(str_ptr, &str_ptr, 16);
  177. DHD_INFO(("%s :got pno_repeat=%d\n", __FUNCTION__, pno_repeat));
  178. if (str_ptr[0] != PNO_TLV_FREQ_EXPO_MAX) {
  179. DBG_871X("%s FREQ_EXPO_MAX corrupted field size\n",
  180. __FUNCTION__);
  181. goto exit_proc;
  182. }
  183. str_ptr++;
  184. pno_freq_expo_max = simple_strtoul(str_ptr, &str_ptr, 16);
  185. DHD_INFO(("%s: pno_freq_expo_max=%d\n",
  186. __FUNCTION__, pno_freq_expo_max));
  187. }
  188. }
  189. } else {
  190. DBG_871X("%s get wrong TLV command\n", __FUNCTION__);
  191. goto exit_proc;
  192. }
  193. res = dhd_dev_pno_set(dev, ssids_local, nssid, pno_time, pno_repeat, pno_freq_expo_max);
  194. exit_proc:
  195. return res;
  196. }
  197. #endif /* PNO_SUPPORT */
  198. int rtw_android_cmdstr_to_num(char *cmdstr)
  199. {
  200. int cmd_num;
  201. for(cmd_num=0 ; cmd_num<ANDROID_WIFI_CMD_MAX; cmd_num++)
  202. if(0 == strnicmp(cmdstr , android_wifi_cmd_str[cmd_num], strlen(android_wifi_cmd_str[cmd_num])) )
  203. break;
  204. return cmd_num;
  205. }
  206. int rtw_android_get_rssi(struct net_device *net, char *command, int total_len)
  207. {
  208. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  209. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  210. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  211. int bytes_written = 0;
  212. if(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) {
  213. bytes_written += snprintf(&command[bytes_written], total_len, "%s rssi %d",
  214. pcur_network->network.Ssid.Ssid, padapter->recvpriv.rssi);
  215. }
  216. return bytes_written;
  217. }
  218. int rtw_android_get_link_speed(struct net_device *net, char *command, int total_len)
  219. {
  220. _adapter *padapter = (_adapter *)rtw_netdev_priv(net);
  221. struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
  222. struct wlan_network *pcur_network = &pmlmepriv->cur_network;
  223. int bytes_written = 0;
  224. u16 link_speed = 0;
  225. link_speed = rtw_get_cur_max_rate(padapter)/10;
  226. bytes_written = snprintf(command, total_len, "LinkSpeed %d", link_speed);
  227. return bytes_written;
  228. }
  229. int rtw_android_get_macaddr(struct net_device *net, char *command, int total_len)
  230. {
  231. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  232. int bytes_written = 0;
  233. bytes_written = snprintf(command, total_len, "Macaddr = "MAC_FMT, MAC_ARG(net->dev_addr));
  234. return bytes_written;
  235. }
  236. int rtw_android_set_country(struct net_device *net, char *command, int total_len)
  237. {
  238. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  239. char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
  240. int ret;
  241. ret = rtw_set_country(adapter, country_code);
  242. return (ret==_SUCCESS)?0:-1;
  243. }
  244. int rtw_android_get_p2p_dev_addr(struct net_device *net, char *command, int total_len)
  245. {
  246. int ret;
  247. int bytes_written = 0;
  248. //We use the same address as our HW MAC address
  249. _rtw_memcpy(command, net->dev_addr, ETH_ALEN);
  250. bytes_written = ETH_ALEN;
  251. return bytes_written;
  252. }
  253. int rtw_android_set_block(struct net_device *net, char *command, int total_len)
  254. {
  255. int ret;
  256. _adapter *adapter = (_adapter *)rtw_netdev_priv(net);
  257. char *block_value = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_BLOCK]) + 1;
  258. #ifdef CONFIG_IOCTL_CFG80211
  259. wdev_to_priv(adapter->rtw_wdev)->block = (*block_value=='0')?_FALSE:_TRUE;
  260. #endif
  261. return 0;
  262. }
  263. int get_int_from_command( char* pcmd )
  264. {
  265. int i = 0;
  266. for( i = 0; i < strlen( pcmd ); i++ )
  267. {
  268. if ( pcmd[ i ] == '=' )
  269. {
  270. // Skip the '=' and space characters.
  271. i += 2;
  272. break;
  273. }
  274. }
  275. return ( rtw_atoi( pcmd + i ) );
  276. }
  277. int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
  278. {
  279. int ret = 0;
  280. char *command = NULL;
  281. int cmd_num;
  282. int bytes_written = 0;
  283. android_wifi_priv_cmd priv_cmd;
  284. rtw_lock_suspend();
  285. if (!ifr->ifr_data) {
  286. ret = -EINVAL;
  287. goto exit;
  288. }
  289. if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(android_wifi_priv_cmd))) {
  290. ret = -EFAULT;
  291. goto exit;
  292. }
  293. //DBG_871X("%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);
  294. command = rtw_zmalloc(priv_cmd.total_len);
  295. if (!command)
  296. {
  297. DBG_871X("%s: failed to allocate memory\n", __FUNCTION__);
  298. ret = -ENOMEM;
  299. goto exit;
  300. }
  301. #if (LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0))
  302. if (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)) {
  303. #else
  304. if (!access_ok(priv_cmd.buf, priv_cmd.total_len)) {
  305. #endif
  306. DBG_871X("%s: failed to access memory\n", __FUNCTION__);
  307. ret = -EFAULT;
  308. goto exit;
  309. }
  310. if (copy_from_user(command, (void *)priv_cmd.buf, priv_cmd.total_len)) {
  311. ret = -EFAULT;
  312. goto exit;
  313. }
  314. DBG_871X("%s: Android private cmd \"%s\" on %s\n"
  315. , __FUNCTION__, command, ifr->ifr_name);
  316. cmd_num = rtw_android_cmdstr_to_num(command);
  317. switch(cmd_num) {
  318. case ANDROID_WIFI_CMD_START:
  319. //bytes_written = wl_android_wifi_on(net);
  320. goto response;
  321. case ANDROID_WIFI_CMD_SETFWPATH:
  322. goto response;
  323. }
  324. if (!g_wifi_on) {
  325. DBG_871X("%s: Ignore private cmd \"%s\" - iface %s is down\n"
  326. ,__FUNCTION__, command, ifr->ifr_name);
  327. ret = 0;
  328. goto exit;
  329. }
  330. switch(cmd_num) {
  331. case ANDROID_WIFI_CMD_STOP:
  332. //bytes_written = wl_android_wifi_off(net);
  333. break;
  334. case ANDROID_WIFI_CMD_SCAN_ACTIVE:
  335. //rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_ACTIVE);
  336. #ifdef CONFIG_PLATFORM_MSTAR_TITANIA12
  337. #ifdef CONFIG_IOCTL_CFG80211
  338. (wdev_to_priv(net->ieee80211_ptr))->bandroid_scan = _TRUE;
  339. #endif //CONFIG_IOCTL_CFG80211
  340. #endif //CONFIG_PLATFORM_MSTAR_TITANIA12
  341. break;
  342. case ANDROID_WIFI_CMD_SCAN_PASSIVE:
  343. //rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_PASSIVE);
  344. break;
  345. case ANDROID_WIFI_CMD_RSSI:
  346. bytes_written = rtw_android_get_rssi(net, command, priv_cmd.total_len);
  347. break;
  348. case ANDROID_WIFI_CMD_LINKSPEED:
  349. bytes_written = rtw_android_get_link_speed(net, command, priv_cmd.total_len);
  350. break;
  351. case ANDROID_WIFI_CMD_MACADDR:
  352. bytes_written = rtw_android_get_macaddr(net, command, priv_cmd.total_len);
  353. break;
  354. case ANDROID_WIFI_CMD_BLOCK:
  355. bytes_written = rtw_android_set_block(net, command, priv_cmd.total_len);
  356. break;
  357. case ANDROID_WIFI_CMD_RXFILTER_START:
  358. //bytes_written = net_os_set_packet_filter(net, 1);
  359. break;
  360. case ANDROID_WIFI_CMD_RXFILTER_STOP:
  361. //bytes_written = net_os_set_packet_filter(net, 0);
  362. break;
  363. case ANDROID_WIFI_CMD_RXFILTER_ADD:
  364. //int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0';
  365. //bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num);
  366. break;
  367. case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
  368. //int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0';
  369. //bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num);
  370. break;
  371. case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
  372. /* TBD: BTCOEXSCAN-START */
  373. break;
  374. case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
  375. /* TBD: BTCOEXSCAN-STOP */
  376. break;
  377. case ANDROID_WIFI_CMD_BTCOEXMODE:
  378. #if 0
  379. uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
  380. if (mode == 1)
  381. net_os_set_packet_filter(net, 0); /* DHCP starts */
  382. else
  383. net_os_set_packet_filter(net, 1); /* DHCP ends */
  384. #ifdef WL_CFG80211
  385. bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command);
  386. #endif
  387. #endif
  388. break;
  389. case ANDROID_WIFI_CMD_SETSUSPENDOPT:
  390. //bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len);
  391. break;
  392. case ANDROID_WIFI_CMD_SETBAND:
  393. {
  394. uint band = *(command + strlen("SETBAND") + 1) - '0';
  395. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  396. if (padapter->chip_type == RTL8192D)
  397. padapter->setband = band;
  398. break;
  399. }
  400. case ANDROID_WIFI_CMD_GETBAND:
  401. //bytes_written = wl_android_get_band(net, command, priv_cmd.total_len);
  402. break;
  403. case ANDROID_WIFI_CMD_COUNTRY:
  404. bytes_written = rtw_android_set_country(net, command, priv_cmd.total_len);
  405. break;
  406. #ifdef PNO_SUPPORT
  407. case ANDROID_WIFI_CMD_PNOSSIDCLR_SET:
  408. //bytes_written = dhd_dev_pno_reset(net);
  409. break;
  410. case ANDROID_WIFI_CMD_PNOSETUP_SET:
  411. //bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len);
  412. break;
  413. case ANDROID_WIFI_CMD_PNOENABLE_SET:
  414. //uint pfn_enabled = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0';
  415. //bytes_written = dhd_dev_pno_enable(net, pfn_enabled);
  416. break;
  417. #endif
  418. case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
  419. bytes_written = rtw_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
  420. break;
  421. case ANDROID_WIFI_CMD_P2P_SET_NOA:
  422. //int skip = strlen(CMD_P2P_SET_NOA) + 1;
  423. //bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip, priv_cmd.total_len - skip);
  424. break;
  425. case ANDROID_WIFI_CMD_P2P_GET_NOA:
  426. //bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len);
  427. break;
  428. case ANDROID_WIFI_CMD_P2P_SET_PS:
  429. //int skip = strlen(CMD_P2P_SET_PS) + 1;
  430. //bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip, priv_cmd.total_len - skip);
  431. break;
  432. #ifdef CONFIG_IOCTL_CFG80211
  433. case ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE:
  434. {
  435. int skip = strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE]) + 3;
  436. bytes_written = rtw_cfg80211_set_mgnt_wpsp2pie(net, command + skip, priv_cmd.total_len - skip, *(command + skip - 2) - '0');
  437. break;
  438. }
  439. #endif //CONFIG_IOCTL_CFG80211
  440. #ifdef CONFIG_WFD
  441. case ANDROID_WIFI_CMD_WFD_ENABLE:
  442. {
  443. // Commented by Albert 2012/07/24
  444. // We can enable the WFD function by using the following command:
  445. // wpa_cli driver wfd-enable
  446. struct wifi_display_info *pwfd_info;
  447. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  448. pwfd_info = &padapter->wfd_info;
  449. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  450. pwfd_info->wfd_enable = _TRUE;
  451. break;
  452. }
  453. case ANDROID_WIFI_CMD_WFD_DISABLE:
  454. {
  455. // Commented by Albert 2012/07/24
  456. // We can disable the WFD function by using the following command:
  457. // wpa_cli driver wfd-disable
  458. struct wifi_display_info *pwfd_info;
  459. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  460. pwfd_info = &padapter->wfd_info;
  461. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  462. pwfd_info->wfd_enable = _FALSE;
  463. break;
  464. }
  465. case ANDROID_WIFI_CMD_WFD_SET_TCPPORT:
  466. {
  467. // Commented by Albert 2012/07/24
  468. // We can set the tcp port number by using the following command:
  469. // wpa_cli driver wfd-set-tcpport = 554
  470. struct wifi_display_info *pwfd_info;
  471. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  472. pwfd_info = &padapter->wfd_info;
  473. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  474. pwfd_info->rtsp_ctrlport = ( u16 ) get_int_from_command( (char*)priv_cmd.buf );
  475. break;
  476. }
  477. case ANDROID_WIFI_CMD_WFD_SET_MAX_TPUT:
  478. {
  479. break;
  480. }
  481. case ANDROID_WIFI_CMD_WFD_SET_DEVTYPE:
  482. {
  483. // Commented by Albert 2012/08/28
  484. // Specify the WFD device type ( WFD source/primary sink )
  485. struct wifi_display_info *pwfd_info;
  486. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  487. pwfd_info = &padapter->wfd_info;
  488. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  489. {
  490. pwfd_info->wfd_device_type = ( u8 ) get_int_from_command( (char*)priv_cmd.buf );
  491. pwfd_info->wfd_device_type &= WFD_DEVINFO_DUAL;
  492. }
  493. break;
  494. }
  495. #endif
  496. default:
  497. DBG_871X("Unknown PRIVATE command %s - ignored\n", command);
  498. snprintf(command, 3, "OK");
  499. bytes_written = strlen("OK");
  500. }
  501. response:
  502. if (bytes_written >= 0) {
  503. if ((bytes_written == 0) && (priv_cmd.total_len > 0))
  504. command[0] = '\0';
  505. if (bytes_written >= priv_cmd.total_len) {
  506. DBG_871X("%s: bytes_written = %d\n", __FUNCTION__, bytes_written);
  507. bytes_written = priv_cmd.total_len;
  508. } else {
  509. bytes_written++;
  510. }
  511. priv_cmd.used_len = bytes_written;
  512. if (copy_to_user((void *)priv_cmd.buf, command, bytes_written)) {
  513. DBG_871X("%s: failed to copy data to user buffer\n", __FUNCTION__);
  514. ret = -EFAULT;
  515. }
  516. }
  517. else {
  518. ret = bytes_written;
  519. }
  520. exit:
  521. rtw_unlock_suspend();
  522. if (command) {
  523. kfree(command);
  524. }
  525. return ret;
  526. }
  527. /**
  528. * Functions for Android WiFi card detection
  529. */
  530. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  531. static int g_wifidev_registered = 0;
  532. static struct semaphore wifi_control_sem;
  533. static struct wifi_platform_data *wifi_control_data = NULL;
  534. static struct resource *wifi_irqres = NULL;
  535. static int wifi_add_dev(void);
  536. static void wifi_del_dev(void);
  537. int rtw_android_wifictrl_func_add(void)
  538. {
  539. int ret = 0;
  540. sema_init(&wifi_control_sem, 0);
  541. ret = wifi_add_dev();
  542. if (ret) {
  543. DBG_871X("%s: platform_driver_register failed\n", __FUNCTION__);
  544. return ret;
  545. }
  546. g_wifidev_registered = 1;
  547. /* Waiting callback after platform_driver_register is done or exit with error */
  548. if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
  549. ret = -EINVAL;
  550. DBG_871X("%s: platform_driver_register timeout\n", __FUNCTION__);
  551. }
  552. return ret;
  553. }
  554. void rtw_android_wifictrl_func_del(void)
  555. {
  556. if (g_wifidev_registered)
  557. {
  558. wifi_del_dev();
  559. g_wifidev_registered = 0;
  560. }
  561. }
  562. void *wl_android_prealloc(int section, unsigned long size)
  563. {
  564. void *alloc_ptr = NULL;
  565. if (wifi_control_data && wifi_control_data->mem_prealloc) {
  566. alloc_ptr = wifi_control_data->mem_prealloc(section, size);
  567. if (alloc_ptr) {
  568. DBG_871X("success alloc section %d\n", section);
  569. if (size != 0L)
  570. memset(alloc_ptr, 0, size);
  571. return alloc_ptr;
  572. }
  573. }
  574. DBG_871X("can't alloc section %d\n", section);
  575. return NULL;
  576. }
  577. int wifi_get_irq_number(unsigned long *irq_flags_ptr)
  578. {
  579. if (wifi_irqres) {
  580. *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
  581. return (int)wifi_irqres->start;
  582. }
  583. #ifdef CUSTOM_OOB_GPIO_NUM
  584. return CUSTOM_OOB_GPIO_NUM;
  585. #else
  586. return -1;
  587. #endif
  588. }
  589. int wifi_set_power(int on, unsigned long msec)
  590. {
  591. DBG_871X("%s = %d\n", __FUNCTION__, on);
  592. if (wifi_control_data && wifi_control_data->set_power) {
  593. wifi_control_data->set_power(on);
  594. }
  595. if (msec)
  596. msleep(msec);
  597. return 0;
  598. }
  599. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  600. int wifi_get_mac_addr(unsigned char *buf)
  601. {
  602. DBG_871X("%s\n", __FUNCTION__);
  603. if (!buf)
  604. return -EINVAL;
  605. if (wifi_control_data && wifi_control_data->get_mac_addr) {
  606. return wifi_control_data->get_mac_addr(buf);
  607. }
  608. return -EOPNOTSUPP;
  609. }
  610. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
  611. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) || defined(COMPAT_KERNEL_RELEASE)
  612. void *wifi_get_country_code(char *ccode)
  613. {
  614. DBG_871X("%s\n", __FUNCTION__);
  615. if (!ccode)
  616. return NULL;
  617. if (wifi_control_data && wifi_control_data->get_country_code) {
  618. return wifi_control_data->get_country_code(ccode);
  619. }
  620. return NULL;
  621. }
  622. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
  623. static int wifi_set_carddetect(int on)
  624. {
  625. DBG_871X("%s = %d\n", __FUNCTION__, on);
  626. if (wifi_control_data && wifi_control_data->set_carddetect) {
  627. wifi_control_data->set_carddetect(on);
  628. }
  629. return 0;
  630. }
  631. static int wifi_probe(struct platform_device *pdev)
  632. {
  633. struct wifi_platform_data *wifi_ctrl =
  634. (struct wifi_platform_data *)(pdev->dev.platform_data);
  635. DBG_871X("## %s\n", __FUNCTION__);
  636. wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
  637. if (wifi_irqres == NULL)
  638. wifi_irqres = platform_get_resource_byname(pdev,
  639. IORESOURCE_IRQ, "bcm4329_wlan_irq");
  640. wifi_control_data = wifi_ctrl;
  641. wifi_set_power(1, 0); /* Power On */
  642. wifi_set_carddetect(1); /* CardDetect (0->1) */
  643. up(&wifi_control_sem);
  644. return 0;
  645. }
  646. static int wifi_remove(struct platform_device *pdev)
  647. {
  648. struct wifi_platform_data *wifi_ctrl =
  649. (struct wifi_platform_data *)(pdev->dev.platform_data);
  650. DBG_871X("## %s\n", __FUNCTION__);
  651. wifi_control_data = wifi_ctrl;
  652. wifi_set_power(0, 0); /* Power Off */
  653. wifi_set_carddetect(0); /* CardDetect (1->0) */
  654. up(&wifi_control_sem);
  655. return 0;
  656. }
  657. static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
  658. {
  659. DBG_871X("##> %s\n", __FUNCTION__);
  660. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  661. bcmsdh_oob_intr_set(0);
  662. #endif
  663. return 0;
  664. }
  665. static int wifi_resume(struct platform_device *pdev)
  666. {
  667. DBG_871X("##> %s\n", __FUNCTION__);
  668. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  669. if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
  670. bcmsdh_oob_intr_set(1);
  671. #endif
  672. return 0;
  673. }
  674. /* temporarily use these two */
  675. static struct platform_driver wifi_device = {
  676. .probe = wifi_probe,
  677. .remove = wifi_remove,
  678. .suspend = wifi_suspend,
  679. .resume = wifi_resume,
  680. .driver = {
  681. .name = "bcmdhd_wlan",
  682. }
  683. };
  684. static struct platform_driver wifi_device_legacy = {
  685. .probe = wifi_probe,
  686. .remove = wifi_remove,
  687. .suspend = wifi_suspend,
  688. .resume = wifi_resume,
  689. .driver = {
  690. .name = "bcm4329_wlan",
  691. }
  692. };
  693. static int wifi_add_dev(void)
  694. {
  695. DBG_871X("## Calling platform_driver_register\n");
  696. platform_driver_register(&wifi_device);
  697. platform_driver_register(&wifi_device_legacy);
  698. return 0;
  699. }
  700. static void wifi_del_dev(void)
  701. {
  702. DBG_871X("## Unregister platform_driver_register\n");
  703. platform_driver_unregister(&wifi_device);
  704. platform_driver_unregister(&wifi_device_legacy);
  705. }
  706. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */