rtw_android.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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 (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)){
  302. DBG_871X("%s: failed to access memory\n", __FUNCTION__);
  303. ret = -EFAULT;
  304. goto exit;
  305. }
  306. if (copy_from_user(command, (void *)priv_cmd.buf, priv_cmd.total_len)) {
  307. ret = -EFAULT;
  308. goto exit;
  309. }
  310. DBG_871X("%s: Android private cmd \"%s\" on %s\n"
  311. , __FUNCTION__, command, ifr->ifr_name);
  312. cmd_num = rtw_android_cmdstr_to_num(command);
  313. switch(cmd_num) {
  314. case ANDROID_WIFI_CMD_START:
  315. //bytes_written = wl_android_wifi_on(net);
  316. goto response;
  317. case ANDROID_WIFI_CMD_SETFWPATH:
  318. goto response;
  319. }
  320. if (!g_wifi_on) {
  321. DBG_871X("%s: Ignore private cmd \"%s\" - iface %s is down\n"
  322. ,__FUNCTION__, command, ifr->ifr_name);
  323. ret = 0;
  324. goto exit;
  325. }
  326. switch(cmd_num) {
  327. case ANDROID_WIFI_CMD_STOP:
  328. //bytes_written = wl_android_wifi_off(net);
  329. break;
  330. case ANDROID_WIFI_CMD_SCAN_ACTIVE:
  331. //rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_ACTIVE);
  332. #ifdef CONFIG_PLATFORM_MSTAR_TITANIA12
  333. #ifdef CONFIG_IOCTL_CFG80211
  334. (wdev_to_priv(net->ieee80211_ptr))->bandroid_scan = _TRUE;
  335. #endif //CONFIG_IOCTL_CFG80211
  336. #endif //CONFIG_PLATFORM_MSTAR_TITANIA12
  337. break;
  338. case ANDROID_WIFI_CMD_SCAN_PASSIVE:
  339. //rtw_set_scan_mode((_adapter *)rtw_netdev_priv(net), SCAN_PASSIVE);
  340. break;
  341. case ANDROID_WIFI_CMD_RSSI:
  342. bytes_written = rtw_android_get_rssi(net, command, priv_cmd.total_len);
  343. break;
  344. case ANDROID_WIFI_CMD_LINKSPEED:
  345. bytes_written = rtw_android_get_link_speed(net, command, priv_cmd.total_len);
  346. break;
  347. case ANDROID_WIFI_CMD_MACADDR:
  348. bytes_written = rtw_android_get_macaddr(net, command, priv_cmd.total_len);
  349. break;
  350. case ANDROID_WIFI_CMD_BLOCK:
  351. bytes_written = rtw_android_set_block(net, command, priv_cmd.total_len);
  352. break;
  353. case ANDROID_WIFI_CMD_RXFILTER_START:
  354. //bytes_written = net_os_set_packet_filter(net, 1);
  355. break;
  356. case ANDROID_WIFI_CMD_RXFILTER_STOP:
  357. //bytes_written = net_os_set_packet_filter(net, 0);
  358. break;
  359. case ANDROID_WIFI_CMD_RXFILTER_ADD:
  360. //int filter_num = *(command + strlen(CMD_RXFILTER_ADD) + 1) - '0';
  361. //bytes_written = net_os_rxfilter_add_remove(net, TRUE, filter_num);
  362. break;
  363. case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
  364. //int filter_num = *(command + strlen(CMD_RXFILTER_REMOVE) + 1) - '0';
  365. //bytes_written = net_os_rxfilter_add_remove(net, FALSE, filter_num);
  366. break;
  367. case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
  368. /* TBD: BTCOEXSCAN-START */
  369. break;
  370. case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
  371. /* TBD: BTCOEXSCAN-STOP */
  372. break;
  373. case ANDROID_WIFI_CMD_BTCOEXMODE:
  374. #if 0
  375. uint mode = *(command + strlen(CMD_BTCOEXMODE) + 1) - '0';
  376. if (mode == 1)
  377. net_os_set_packet_filter(net, 0); /* DHCP starts */
  378. else
  379. net_os_set_packet_filter(net, 1); /* DHCP ends */
  380. #ifdef WL_CFG80211
  381. bytes_written = wl_cfg80211_set_btcoex_dhcp(net, command);
  382. #endif
  383. #endif
  384. break;
  385. case ANDROID_WIFI_CMD_SETSUSPENDOPT:
  386. //bytes_written = wl_android_set_suspendopt(net, command, priv_cmd.total_len);
  387. break;
  388. case ANDROID_WIFI_CMD_SETBAND:
  389. {
  390. uint band = *(command + strlen("SETBAND") + 1) - '0';
  391. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  392. if (padapter->chip_type == RTL8192D)
  393. padapter->setband = band;
  394. break;
  395. }
  396. case ANDROID_WIFI_CMD_GETBAND:
  397. //bytes_written = wl_android_get_band(net, command, priv_cmd.total_len);
  398. break;
  399. case ANDROID_WIFI_CMD_COUNTRY:
  400. bytes_written = rtw_android_set_country(net, command, priv_cmd.total_len);
  401. break;
  402. #ifdef PNO_SUPPORT
  403. case ANDROID_WIFI_CMD_PNOSSIDCLR_SET:
  404. //bytes_written = dhd_dev_pno_reset(net);
  405. break;
  406. case ANDROID_WIFI_CMD_PNOSETUP_SET:
  407. //bytes_written = wl_android_set_pno_setup(net, command, priv_cmd.total_len);
  408. break;
  409. case ANDROID_WIFI_CMD_PNOENABLE_SET:
  410. //uint pfn_enabled = *(command + strlen(CMD_PNOENABLE_SET) + 1) - '0';
  411. //bytes_written = dhd_dev_pno_enable(net, pfn_enabled);
  412. break;
  413. #endif
  414. case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
  415. bytes_written = rtw_android_get_p2p_dev_addr(net, command, priv_cmd.total_len);
  416. break;
  417. case ANDROID_WIFI_CMD_P2P_SET_NOA:
  418. //int skip = strlen(CMD_P2P_SET_NOA) + 1;
  419. //bytes_written = wl_cfg80211_set_p2p_noa(net, command + skip, priv_cmd.total_len - skip);
  420. break;
  421. case ANDROID_WIFI_CMD_P2P_GET_NOA:
  422. //bytes_written = wl_cfg80211_get_p2p_noa(net, command, priv_cmd.total_len);
  423. break;
  424. case ANDROID_WIFI_CMD_P2P_SET_PS:
  425. //int skip = strlen(CMD_P2P_SET_PS) + 1;
  426. //bytes_written = wl_cfg80211_set_p2p_ps(net, command + skip, priv_cmd.total_len - skip);
  427. break;
  428. #ifdef CONFIG_IOCTL_CFG80211
  429. case ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE:
  430. {
  431. int skip = strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_SET_AP_WPS_P2P_IE]) + 3;
  432. bytes_written = rtw_cfg80211_set_mgnt_wpsp2pie(net, command + skip, priv_cmd.total_len - skip, *(command + skip - 2) - '0');
  433. break;
  434. }
  435. #endif //CONFIG_IOCTL_CFG80211
  436. #ifdef CONFIG_WFD
  437. case ANDROID_WIFI_CMD_WFD_ENABLE:
  438. {
  439. // Commented by Albert 2012/07/24
  440. // We can enable the WFD function by using the following command:
  441. // wpa_cli driver wfd-enable
  442. struct wifi_display_info *pwfd_info;
  443. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  444. pwfd_info = &padapter->wfd_info;
  445. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  446. pwfd_info->wfd_enable = _TRUE;
  447. break;
  448. }
  449. case ANDROID_WIFI_CMD_WFD_DISABLE:
  450. {
  451. // Commented by Albert 2012/07/24
  452. // We can disable the WFD function by using the following command:
  453. // wpa_cli driver wfd-disable
  454. struct wifi_display_info *pwfd_info;
  455. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  456. pwfd_info = &padapter->wfd_info;
  457. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  458. pwfd_info->wfd_enable = _FALSE;
  459. break;
  460. }
  461. case ANDROID_WIFI_CMD_WFD_SET_TCPPORT:
  462. {
  463. // Commented by Albert 2012/07/24
  464. // We can set the tcp port number by using the following command:
  465. // wpa_cli driver wfd-set-tcpport = 554
  466. struct wifi_display_info *pwfd_info;
  467. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  468. pwfd_info = &padapter->wfd_info;
  469. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  470. pwfd_info->rtsp_ctrlport = ( u16 ) get_int_from_command( (char*)priv_cmd.buf );
  471. break;
  472. }
  473. case ANDROID_WIFI_CMD_WFD_SET_MAX_TPUT:
  474. {
  475. break;
  476. }
  477. case ANDROID_WIFI_CMD_WFD_SET_DEVTYPE:
  478. {
  479. // Commented by Albert 2012/08/28
  480. // Specify the WFD device type ( WFD source/primary sink )
  481. struct wifi_display_info *pwfd_info;
  482. _adapter* padapter = ( _adapter * ) rtw_netdev_priv(net);
  483. pwfd_info = &padapter->wfd_info;
  484. if( padapter->wdinfo.driver_interface == DRIVER_CFG80211 )
  485. {
  486. pwfd_info->wfd_device_type = ( u8 ) get_int_from_command( (char*)priv_cmd.buf );
  487. pwfd_info->wfd_device_type &= WFD_DEVINFO_DUAL;
  488. }
  489. break;
  490. }
  491. #endif
  492. default:
  493. DBG_871X("Unknown PRIVATE command %s - ignored\n", command);
  494. snprintf(command, 3, "OK");
  495. bytes_written = strlen("OK");
  496. }
  497. response:
  498. if (bytes_written >= 0) {
  499. if ((bytes_written == 0) && (priv_cmd.total_len > 0))
  500. command[0] = '\0';
  501. if (bytes_written >= priv_cmd.total_len) {
  502. DBG_871X("%s: bytes_written = %d\n", __FUNCTION__, bytes_written);
  503. bytes_written = priv_cmd.total_len;
  504. } else {
  505. bytes_written++;
  506. }
  507. priv_cmd.used_len = bytes_written;
  508. if (copy_to_user((void *)priv_cmd.buf, command, bytes_written)) {
  509. DBG_871X("%s: failed to copy data to user buffer\n", __FUNCTION__);
  510. ret = -EFAULT;
  511. }
  512. }
  513. else {
  514. ret = bytes_written;
  515. }
  516. exit:
  517. rtw_unlock_suspend();
  518. if (command) {
  519. kfree(command);
  520. }
  521. return ret;
  522. }
  523. /**
  524. * Functions for Android WiFi card detection
  525. */
  526. #if defined(RTW_ENABLE_WIFI_CONTROL_FUNC)
  527. static int g_wifidev_registered = 0;
  528. static struct semaphore wifi_control_sem;
  529. static struct wifi_platform_data *wifi_control_data = NULL;
  530. static struct resource *wifi_irqres = NULL;
  531. static int wifi_add_dev(void);
  532. static void wifi_del_dev(void);
  533. int rtw_android_wifictrl_func_add(void)
  534. {
  535. int ret = 0;
  536. sema_init(&wifi_control_sem, 0);
  537. ret = wifi_add_dev();
  538. if (ret) {
  539. DBG_871X("%s: platform_driver_register failed\n", __FUNCTION__);
  540. return ret;
  541. }
  542. g_wifidev_registered = 1;
  543. /* Waiting callback after platform_driver_register is done or exit with error */
  544. if (down_timeout(&wifi_control_sem, msecs_to_jiffies(1000)) != 0) {
  545. ret = -EINVAL;
  546. DBG_871X("%s: platform_driver_register timeout\n", __FUNCTION__);
  547. }
  548. return ret;
  549. }
  550. void rtw_android_wifictrl_func_del(void)
  551. {
  552. if (g_wifidev_registered)
  553. {
  554. wifi_del_dev();
  555. g_wifidev_registered = 0;
  556. }
  557. }
  558. void *wl_android_prealloc(int section, unsigned long size)
  559. {
  560. void *alloc_ptr = NULL;
  561. if (wifi_control_data && wifi_control_data->mem_prealloc) {
  562. alloc_ptr = wifi_control_data->mem_prealloc(section, size);
  563. if (alloc_ptr) {
  564. DBG_871X("success alloc section %d\n", section);
  565. if (size != 0L)
  566. memset(alloc_ptr, 0, size);
  567. return alloc_ptr;
  568. }
  569. }
  570. DBG_871X("can't alloc section %d\n", section);
  571. return NULL;
  572. }
  573. int wifi_get_irq_number(unsigned long *irq_flags_ptr)
  574. {
  575. if (wifi_irqres) {
  576. *irq_flags_ptr = wifi_irqres->flags & IRQF_TRIGGER_MASK;
  577. return (int)wifi_irqres->start;
  578. }
  579. #ifdef CUSTOM_OOB_GPIO_NUM
  580. return CUSTOM_OOB_GPIO_NUM;
  581. #else
  582. return -1;
  583. #endif
  584. }
  585. int wifi_set_power(int on, unsigned long msec)
  586. {
  587. DBG_871X("%s = %d\n", __FUNCTION__, on);
  588. if (wifi_control_data && wifi_control_data->set_power) {
  589. wifi_control_data->set_power(on);
  590. }
  591. if (msec)
  592. msleep(msec);
  593. return 0;
  594. }
  595. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
  596. int wifi_get_mac_addr(unsigned char *buf)
  597. {
  598. DBG_871X("%s\n", __FUNCTION__);
  599. if (!buf)
  600. return -EINVAL;
  601. if (wifi_control_data && wifi_control_data->get_mac_addr) {
  602. return wifi_control_data->get_mac_addr(buf);
  603. }
  604. return -EOPNOTSUPP;
  605. }
  606. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)) */
  607. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) || defined(COMPAT_KERNEL_RELEASE)
  608. void *wifi_get_country_code(char *ccode)
  609. {
  610. DBG_871X("%s\n", __FUNCTION__);
  611. if (!ccode)
  612. return NULL;
  613. if (wifi_control_data && wifi_control_data->get_country_code) {
  614. return wifi_control_data->get_country_code(ccode);
  615. }
  616. return NULL;
  617. }
  618. #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)) */
  619. static int wifi_set_carddetect(int on)
  620. {
  621. DBG_871X("%s = %d\n", __FUNCTION__, on);
  622. if (wifi_control_data && wifi_control_data->set_carddetect) {
  623. wifi_control_data->set_carddetect(on);
  624. }
  625. return 0;
  626. }
  627. static int wifi_probe(struct platform_device *pdev)
  628. {
  629. struct wifi_platform_data *wifi_ctrl =
  630. (struct wifi_platform_data *)(pdev->dev.platform_data);
  631. DBG_871X("## %s\n", __FUNCTION__);
  632. wifi_irqres = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "bcmdhd_wlan_irq");
  633. if (wifi_irqres == NULL)
  634. wifi_irqres = platform_get_resource_byname(pdev,
  635. IORESOURCE_IRQ, "bcm4329_wlan_irq");
  636. wifi_control_data = wifi_ctrl;
  637. wifi_set_power(1, 0); /* Power On */
  638. wifi_set_carddetect(1); /* CardDetect (0->1) */
  639. up(&wifi_control_sem);
  640. return 0;
  641. }
  642. static int wifi_remove(struct platform_device *pdev)
  643. {
  644. struct wifi_platform_data *wifi_ctrl =
  645. (struct wifi_platform_data *)(pdev->dev.platform_data);
  646. DBG_871X("## %s\n", __FUNCTION__);
  647. wifi_control_data = wifi_ctrl;
  648. wifi_set_power(0, 0); /* Power Off */
  649. wifi_set_carddetect(0); /* CardDetect (1->0) */
  650. up(&wifi_control_sem);
  651. return 0;
  652. }
  653. static int wifi_suspend(struct platform_device *pdev, pm_message_t state)
  654. {
  655. DBG_871X("##> %s\n", __FUNCTION__);
  656. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  657. bcmsdh_oob_intr_set(0);
  658. #endif
  659. return 0;
  660. }
  661. static int wifi_resume(struct platform_device *pdev)
  662. {
  663. DBG_871X("##> %s\n", __FUNCTION__);
  664. #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 39)) && defined(OOB_INTR_ONLY)
  665. if (dhd_os_check_if_up(bcmsdh_get_drvdata()))
  666. bcmsdh_oob_intr_set(1);
  667. #endif
  668. return 0;
  669. }
  670. /* temporarily use these two */
  671. static struct platform_driver wifi_device = {
  672. .probe = wifi_probe,
  673. .remove = wifi_remove,
  674. .suspend = wifi_suspend,
  675. .resume = wifi_resume,
  676. .driver = {
  677. .name = "bcmdhd_wlan",
  678. }
  679. };
  680. static struct platform_driver wifi_device_legacy = {
  681. .probe = wifi_probe,
  682. .remove = wifi_remove,
  683. .suspend = wifi_suspend,
  684. .resume = wifi_resume,
  685. .driver = {
  686. .name = "bcm4329_wlan",
  687. }
  688. };
  689. static int wifi_add_dev(void)
  690. {
  691. DBG_871X("## Calling platform_driver_register\n");
  692. platform_driver_register(&wifi_device);
  693. platform_driver_register(&wifi_device_legacy);
  694. return 0;
  695. }
  696. static void wifi_del_dev(void)
  697. {
  698. DBG_871X("## Unregister platform_driver_register\n");
  699. platform_driver_unregister(&wifi_device);
  700. platform_driver_unregister(&wifi_device_legacy);
  701. }
  702. #endif /* defined(RTW_ENABLE_WIFI_CONTROL_FUNC) */