找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5654|回复: 0
打印 上一主题 下一主题
收起左侧

STM32 wifi无线遥控器设计 在网页端控制单片机LED的亮灭

[复制链接]
跳转到指定楼层
楼主
无线遥控器设计的课程作业
简化的设计,在网页端控制开发板LED的亮灭。
使用udp传输协议,可以较好的穿透内网,
实现端端之间的直接通信。




STM32MARVELL88芯片主控

单片机源程序如下:
  1. #define DEBUG
  2. #include "drivers.h"
  3. #include "app.h"
  4. #include "api.h"

  5. #include "cfg80211.h"
  6. #include "defs.h"
  7. #include "type.h"
  8. #include "types.h"

  9. #include "moal_sdio.h"
  10. #include "lwip/pbuf.h"
  11. #include "lwip/sys.h"
  12. #include "wpa.h"

  13. #include "moal_main.h"
  14. #include "moal_uap.h"
  15. #include "moal_uap_priv.h"
  16. #include "mlan_ioctl.h"

  17. #include "oled.h"

  18. /*
  19. *分为station和ap两个设备,其接口函数是不一样的
  20. *所以在不同的模式下我们选择相对应的设备进行操作
  21. *wifi_dev指向当前设备
  22. */
  23. struct net_device *sta_wifi_dev = NULL;
  24. struct net_device *ap_wifi_dev = NULL;
  25. struct net_device *direct_wifi_dev = NULL;

  26. struct net_device *wifi_dev = NULL;

  27. struct net_device *get_wifi_dev()
  28. {
  29.         return wifi_dev;
  30. }

  31. int is_hw_ok()
  32. {
  33.         return wifi_dev?1:0;
  34. }

  35. /**
  36. * @brief  设置wifi模式,只是切换模式,不对ap参数进行配置
  37. * @param  type : MODE_AP, MODE_STATION, MODE_ADHOC
  38. * @retval ok: 0, err: -1
  39. */
  40. int wifi_set_mode(int type)
  41. {
  42.         int ret = -1;
  43.         int set_type;
  44.         moal_private *priv;
  45.         struct net_device *saved_dev = wifi_dev;

  46.         priv = (moal_private *)wifi_dev->ml_priv;
  47.         //暂不支持ap+sta同时存在,切换模式前先关闭wifi
  48.         if(priv->bss_role == MLAN_BSS_ROLE_UAP)
  49.                 wifi_stop_ap();
  50.         else
  51.                 wifi_disconnect();
  52.         if(0)
  53.                 ;
  54. #ifdef UAP_SUPPORT               
  55.         else if(type == MODE_AP){
  56.                 set_type = NL80211_IFTYPE_AP;
  57.                 wifi_dev = ap_wifi_dev;
  58.                 OLED_ShowString(16,2,"  MODE:AP   ");
  59.                 OLED_ShowString(0,0,"IP:");
  60.                 OLED_ShowString(24,0,"192.168.1.8");
  61.                 p_dbg("IP:192.168.1.8");
  62.         }
  63. #endif
  64. #ifdef STA_SUPPORT       
  65.         else if(type == MODE_STATION){
  66.                 wifi_dev = sta_wifi_dev;
  67.                 set_type = NL80211_IFTYPE_STATION;
  68.                 OLED_ShowString(16,2,"MODE:STATION");
  69.         }

  70.         else if(type == MODE_ADHOC){
  71.                 wifi_dev = sta_wifi_dev;
  72.                 set_type = NL80211_IFTYPE_ADHOC;
  73.                 OLED_ShowString(16,2," MODE:ADHOC ");
  74.         }
  75. #endif
  76. #ifdef WIFI_DIRECT_SUPPORT       
  77.         else if(type == MODE_P2P_GO){
  78.                 wifi_dev = direct_wifi_dev;
  79.                 set_type = NL80211_IFTYPE_P2P_GO;
  80.         }
  81.         else if(type == MODE_P2P_GC){
  82.                 wifi_dev = direct_wifi_dev;
  83.                 set_type = NL80211_IFTYPE_P2P_CLIENT;
  84.         }
  85. #endif
  86.         else{
  87.                 p_err("type %d not support", type);
  88.                 return -1;
  89.         }

  90.         if(wifi_dev == NULL){
  91.                
  92.                 wifi_dev = saved_dev;
  93.                 p_err("%s not support", __FUNCTION__);
  94.                 return -1;
  95.         }

  96.         if(wifi_dev->cfg80211_ops->change_virtual_intf){
  97.                 priv = (moal_private *)wifi_dev->ml_priv;

  98.                 //ap和sta指向相同的change_virtual_intf
  99.                 ret = wifi_dev->cfg80211_ops->change_virtual_intf(priv->wdev->wiphy, wifi_dev, (enum nl80211_iftype)set_type, 0, 0);
  100.                 if(ret != 0)
  101.                 {
  102.                         wifi_dev = saved_dev;
  103.                 }
  104.         }else
  105.                 p_err("%s not support", __FUNCTION__);

  106.         return ret;
  107. }


  108. /**
  109. * @brief  设置硬件的多播、广播、混杂模式
  110. * @param  flags :  IFF_PROMISC        接收所有的包
  111.                                 IFF_ALLMULTI 接收所有的多播包(暂时采用接收所有多播报的简单方式,
  112.                                 不处理多播地址表)

  113. * @retval ok: 0, err: -1
  114. */
  115. int wifi_set_multicast(uint32_t flags)
  116. {
  117.         if(!wifi_dev)
  118.                 return -1;
  119.        
  120.         wifi_dev->flags |= flags;

  121.         if(wifi_dev->netdev_ops && wifi_dev->netdev_ops->ndo_set_multicast_list)
  122.                 wifi_dev->netdev_ops->ndo_set_multicast_list(wifi_dev);
  123.        
  124.         return 0;
  125. }


  126. /**
  127. * @brief  设置为混杂模式
  128. * @param  
  129. * @retval ok: 0, err: -1
  130. */
  131. int wifi_set_promisc()
  132. {
  133.         return wifi_set_multicast(IFF_PROMISC);
  134. }


  135. /**
  136. * @brief  设置wifi频道,for ap
  137. * @param  channel : 1 - 14
  138. * @retval ok: 0, err: -1
  139. */
  140. int wifi_set_channel(int channel)
  141. {
  142.         int ret = -1;
  143.         struct ieee80211_channel ch;
  144.         moal_private *priv;

  145.         //sta和ap的cfg80211_ops接口是不一样的,必须检查其成员是否有效,下同
  146.         if(wifi_dev->cfg80211_ops->set_channel){
  147.                 priv = (moal_private *)wifi_dev->ml_priv;

  148.                 memset(&ch, 0, sizeof(struct ieee80211_channel));
  149.                 ch.hw_value = channel;
  150.                 ch.band = IEEE80211_BAND_2GHZ;
  151.                 ch.center_freq = ieee80211_channel_to_frequency(ch.hw_value, ch.band);
  152.                
  153.                 //ap和sta指向相同的change_virtual_intf
  154.                 ret = wifi_dev->cfg80211_ops->set_channel(priv->wdev->wiphy, wifi_dev, &ch, NL80211_CHAN_NO_HT);
  155.         }else
  156.                 p_err("%s not support", __FUNCTION__);
  157.        
  158.         return ret;
  159. }


  160. /**
  161. * @brief  设置wifi模式为AP参数
  162. *
  163. * @param  name : 网络名称
  164. * @param  key:密码
  165. * @param  key_type:加密模式,可选参数KEY_NONE, KEY_WEP,KEY_WPA,KEY_WPA2
  166. * @param  channel:频道
  167. * @param  max_client:最大允许客户端数量,1 - MAX_STA_COUNT(SDK预设为10)
  168. *
  169. * @retval ok: 0, err: -1
  170. */
  171. int wifi_ap_cfg(char *name, char *key, int key_type, int channel, int max_client)
  172. {
  173.         int ret = -1;
  174.         char str_tmp[64];
  175.         /* example
  176.         char *cmd = "ASCII_CMD=AP_CFG,"\
  177.         "SSID=QWERT,"\
  178.         "SEC=wep128,"\
  179.         "KEY=12345,"\
  180.         "CHANNEL=8,"\
  181.         "MAX_SCB=4,"\
  182.         "END";
  183.         */

  184.         //配置ap参数我们没有使用cfg80211_ops提供的, 而是使用更简单的netdev_ops接口
  185.         //netdev_ops接口比较丰富,这里做一个参考
  186.         if(wifi_dev->netdev_ops && wifi_dev->netdev_ops->ndo_do_ioctl)
  187.         {
  188.                 struct iwreq *wrq = (struct iwreq *)mem_calloc(256, 1);

  189.                 if(!wrq)
  190.                         return ret;
  191.                
  192.                 wrq->u.data.pointer = wrq + 1;
  193.                 strcpy(wrq->u.data.pointer, "ASCII_CMD=AP_CFG,");

  194.                 snprintf(str_tmp, 64, "SSID=%s,", name);
  195.                 strcat(wrq->u.data.pointer, str_tmp);

  196.                 if (key_type == KEY_NONE)
  197.                         strcpy(str_tmp, "SEC=open,");
  198.                 else if (key_type == KEY_WEP)
  199.                         strcpy(str_tmp, "SEC=wep128,");
  200.                 else if (key_type == KEY_WPA)
  201.                         strcpy(str_tmp, "SEC=wpa-psk,");
  202.                 else if (key_type == KEY_WPA2)
  203.                         strcpy(str_tmp, "SEC=wpa2-psk,");
  204.                 else
  205.                         strcpy(str_tmp, "SEC=open,");
  206.                
  207.                 strcat(wrq->u.data.pointer, str_tmp);

  208.                 snprintf(str_tmp, 64, "KEY=%s,", key);
  209.                 strcat(wrq->u.data.pointer, str_tmp);

  210.                 snprintf(str_tmp, 64, "CHANNEL=%d,", channel);
  211.                 strcat(wrq->u.data.pointer, str_tmp);

  212.                 snprintf(str_tmp, 64, "MAX_SCB=%d,", max_client);
  213.                 strcat(wrq->u.data.pointer, str_tmp);

  214.                 strcat(wrq->u.data.pointer, "END");

  215.                 wrq->u.data.length = strlen(wrq->u.data.pointer);
  216.                
  217.                 ret = wifi_dev->netdev_ops->ndo_do_ioctl(wifi_dev, (void*)wrq, WOAL_UAP_FROYO_AP_SET_CFG);
  218.                 if(ret == 0)
  219.                         ret = wifi_dev->netdev_ops->ndo_do_ioctl(wifi_dev, 0, WOAL_UAP_FROYO_AP_BSS_START);

  220.                 mem_free(wrq);

  221.         }else
  222.                 p_err("%s not support", __FUNCTION__);
  223.        
  224.         return ret;
  225. }


  226. int wifi_stop_ap()
  227. {
  228.         int ret = -1;
  229.        
  230.         if(wifi_dev->netdev_ops && wifi_dev->netdev_ops->ndo_do_ioctl)
  231.         {
  232.                 ret = wifi_dev->netdev_ops->ndo_do_ioctl(wifi_dev, 0, WOAL_UAP_FROYO_AP_BSS_STOP);
  233.         }
  234.         return ret;
  235. }


  236. /**
  237. * @brief
  238. */
  239. int wifi_join_adhoc(char *ssid, char *key, int ch)
  240. {
  241.         int ret = -1;
  242.         moal_private *priv;
  243.         struct cfg80211_ibss_params params;
  244.         struct ieee80211_channel channel;
  245.         int key_len = strlen(key);
  246.        
  247.         memset(¶ms, 0, sizeof(struct cfg80211_ibss_params));
  248.         memset(&channel, 0 ,sizeof(struct ieee80211_channel));

  249.         params.channel = &channel;
  250.        
  251.         params.beacon_interval = 100;
  252.         params.ssid = (u8*)ssid;
  253.         params.ssid_len = strlen(ssid);
  254.         params.channel_fixed = TRUE;
  255.         params.channel->band = IEEE80211_BAND_2GHZ;
  256.         params.channel->hw_value = ch;
  257.         params.channel->center_freq = ieee80211_channel_to_frequency(params.channel->hw_value,
  258.                 params.channel->band);
  259.         if(key_len)
  260.         {
  261.                 params.key = key;
  262.                 params.key_len = key_len;
  263.                 params.privacy = TRUE;        //使能wep加密
  264.         }
  265.        
  266.         priv = (moal_private *)wifi_dev->ml_priv;
  267.         if(wifi_dev->cfg80211_ops && wifi_dev->cfg80211_ops->join_ibss)
  268.         {
  269.                 ret = wifi_dev->cfg80211_ops->join_ibss(priv->wdev->wiphy, wifi_dev, ¶ms);

  270.         }else
  271.                 p_err("%s not support", __FUNCTION__);
  272.        
  273.         return ret;
  274. }


  275. int wifi_leave_adhoc()
  276. {
  277.         int ret = -1;
  278.         moal_private *priv;
  279.        
  280.         priv = (moal_private *)wifi_dev->ml_priv;
  281.         if(wifi_dev->cfg80211_ops && wifi_dev->cfg80211_ops->leave_ibss)
  282.         {
  283.                 ret = wifi_dev->cfg80211_ops->leave_ibss(priv->wdev->wiphy, wifi_dev);

  284.         }else
  285.                 p_err("%s not support", __FUNCTION__);
  286.        
  287.         return ret;
  288. }

  289. #ifdef UAP_SUPPORT
  290. int wifi_get_sta_list(mlan_ds_sta_list *p_list)
  291. {
  292.         int ret = -1;
  293.        
  294.         if(wifi_dev->netdev_ops && wifi_dev->netdev_ops->ndo_do_ioctl)
  295.         {
  296.                 struct iwreq *wrq = (struct iwreq *)mem_calloc(sizeof(struct iwreq), 1);
  297.                 if(wrq)
  298.                 {
  299.                         wrq->u.data.pointer = p_list;
  300.                
  301.                         ret = wifi_dev->netdev_ops->ndo_do_ioctl(wifi_dev, (void*)wrq, UAP_GET_STA_LIST);

  302.                         mem_free(wrq);
  303.                 }
  304.                
  305.         }else
  306.                 p_err("%s not support", __FUNCTION__);
  307.        
  308.         return ret;
  309.        
  310. }
  311. #endif

  312. struct cfg80211_scan_request *new_scan_req(moal_private *priv, char *ssid, u8_t ssid_len)
  313. {
  314.         struct wiphy *wiphy = priv->wdev->wiphy;
  315.         struct cfg80211_scan_request *creq = NULL;
  316.         int i, n_channels = 0;
  317.         enum ieee80211_band band;

  318.         for (band = (enum ieee80211_band)0; band < IEEE80211_NUM_BANDS; band++) {
  319.                 if (wiphy->bands[band])
  320.                         n_channels += wiphy->bands[band]->n_channels;
  321.         }

  322.         p_dbg("_new_connect_scan_req,channels:%d,creq_size:%d\n",n_channels,sizeof(*creq) + sizeof(struct cfg80211_ssid) +
  323.                        n_channels * sizeof(void *));
  324.         creq = (struct cfg80211_scan_request *)mem_calloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
  325.                        n_channels * sizeof(void *),1);
  326.         if (!creq)
  327.                 return NULL;
  328.         /* SSIDs come after channels */
  329.         creq->wiphy = wiphy;
  330.         creq->ssids = (void *)&creq->channels[n_channels];
  331.         creq->n_channels = n_channels;
  332.         if(ssid_len)
  333.                 creq->n_ssids = 1;

  334.         /* Scan all available channels */
  335.         i = 0;
  336.         for (band = (enum ieee80211_band)0; band < IEEE80211_NUM_BANDS; band++) {
  337.                 int j;

  338.                 if (!wiphy->bands[band])
  339.                         continue;

  340.                 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  341.                         /* ignore disabled channels */
  342.                         if (wiphy->bands[band]->channels[j].flags &
  343.                                                 IEEE80211_CHAN_DISABLED)
  344.                                 continue;

  345.                         creq->channels[i] = &wiphy->bands[band]->channels[j];
  346.                         i++;
  347.                 }
  348.         }
  349.         if (i) {
  350.                 /* Set real number of channels specified in creq->channels[] */
  351.                 creq->n_channels = i;

  352.                 /* Scan for the SSID we're going to connect to */
  353.                 memcpy(creq->ssids[0].ssid, ssid, ssid_len);
  354.                 creq->ssids[0].ssid_len = ssid_len;
  355.         } else {
  356.                 /* No channels found... */
  357.                 mem_free(creq);
  358.                 creq = NULL;
  359.         }

  360.         return creq;
  361. }


  362. /**
  363. * @brief  扫描附近的AP,usr_scan_result_callback是我们自定义的一个回调接口
  364. *                每扫描到一个ap就会在wlan_ret_802_11_scan->handle_user_scan_result调用一次,其参数scan_result_data包含一些基本
  365. *                的ap信息,一般已经够用,如果要更详细的ap的信息请直接在handle_user_scan_result里面取
  366. * @param
  367. * @retval ok: 0, err: -1
  368. */
  369. extern void (*usr_scan_result_callback)(struct scan_result_data *res_data);

  370. int wifi_scan(void (*scan_result_callback)(struct scan_result_data *res_data),
  371.                 char *essid)
  372. {
  373.         moal_private *priv;
  374.         struct cfg80211_scan_request *scan_request;
  375.        
  376.         if(!wifi_dev)
  377.                 return -1;
  378.         priv = (moal_private *)wifi_dev->ml_priv;

  379.         if(priv->bss_role == MLAN_BSS_ROLE_UAP)
  380.         {
  381.                 p_err("AP模式下不支持scan,请先切换到STA模式");
  382.                 return 0;
  383.         }
  384.        
  385.         usr_scan_result_callback = scan_result_callback;
  386.         scan_request = new_scan_req(priv, essid, strlen(essid));
  387.         wifi_dev->cfg80211_ops->scan(priv->wdev->wiphy, wifi_dev, scan_request);

  388.         //scan是异步实现的,这里调用完会马上退出
  389.         //扫描完成后驱动会自动调用cfg80211_scan_done函数

  390.         return 0;
  391. }


  392. /**
  393. * @brief  wifi 是否已经连接
  394. *
  395. */
  396. int is_wifi_connected()
  397. {

  398.         int ret = 0;
  399.         moal_private *priv;
  400.         priv = (moal_private *)wifi_dev->ml_priv;
  401.        
  402.         if(priv->media_connected)
  403.                 ret = 1;

  404.         return ret;
  405. }

  406. /**
  407. * @brief  wifi连接,驱动自动处理加密模式和频道,用户只需提供路由器名称和密码
  408. * @param
  409. *                                                       
  410. *                essid: 即AP名称
  411. *                key: 明文密码       
  412. * @retval ok: 0, err: -1
  413. */
  414. int wifi_connect( char *essid, char *key)
  415. {

  416.         int result_ret = 0;
  417.         moal_private *priv;
  418.         int essid_len = strlen(essid);
  419.         int key_len = strlen(key);
  420.         struct cfg80211_connect_params *smee = 0;
  421.        
  422.         p_dbg("enter %s\n", __FUNCTION__);
  423.         OLED_ShowString(0,4,"SSID:");
  424.         OLED_ShowString(0,6,"KEY:");

  425.         OLED_ShowString(48,4,(u8 *)essid);
  426.         OLED_ShowString(48,6,(u8 *)key);

  427.         if(essid_len > 32 || key_len > 32)
  428.         {
  429.                 result_ret = -1;
  430.                 goto ret;
  431.         }
  432.         smee = (struct cfg80211_connect_params *)mem_malloc(sizeof(struct cfg80211_connect_params));
  433.         if(smee == 0)
  434.         {
  435.                 result_ret = -1;
  436.                 goto ret;
  437.         }

  438.         priv = (moal_private *)wifi_dev->ml_priv;
  439.         memset(smee,0,sizeof(struct cfg80211_connect_params));
  440.         smee->bssid = 0;
  441.        
  442.         memcpy(smee->ssid,essid,essid_len);
  443.         smee->ssid[essid_len] = 0;
  444.        
  445.         smee->ssid_len = essid_len;
  446.        
  447.         memcpy(smee->key,key,key_len);
  448.         smee->key[key_len] = 0;
  449.        
  450.         smee->key_len = key_len;
  451.         smee->auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  452.         smee->crypto.wpa_versions = NL80211_WPA_VERSION_2;
  453.         smee->crypto.cipher_group = MLAN_ENCRYPTION_MODE_CCMP;
  454.         smee->crypto.n_ciphers_pairwise = 1;
  455.         smee->crypto.ciphers_pairwise[0] = MLAN_ENCRYPTION_MODE_CCMP;

  456. /*
  457. *smee结构只填充了部分成员,其他成员将在连接的时候自动填充(根据目标ap的信息)
  458. */
  459.        
  460.         result_ret = wifi_dev->cfg80211_ops->wifi_connect(priv->wdev->wiphy, wifi_dev,smee);
  461. ret:
  462.         if(smee)
  463.                 mem_free(smee);
  464.         if(result_ret)
  465.                 p_err("user_link_app err:%d\n",result_ret);

  466.         p_dbg("exit %s\n", __FUNCTION__);
  467.        
  468.         return result_ret;
  469. }

  470. /**
  471. * @brief  断开连接
  472. */
  473. int wifi_disconnect()
  474. {
  475.         int ret = -1;
  476.         moal_private *priv;
  477.        
  478.         priv = (moal_private *)wifi_dev->ml_priv;
  479.         if(wifi_dev->cfg80211_ops && wifi_dev->cfg80211_ops->disconnect)
  480.         {
  481.                 ret = wifi_dev->cfg80211_ops->disconnect(priv->wdev->wiphy, wifi_dev, 0);

  482.         }else
  483.                 p_err("%s not support", __FUNCTION__);
  484.        
  485.        
  486.         return ret;
  487. }


  488. /**
  489. * @brief  读取mac地址,mac地址从8782芯片读取
  490. * @param  mac_addr : mac地址 6BYTE
  491. */
  492. int wifi_get_mac(unsigned char *mac_addr)
  493. {
  494.        
  495.         memcpy(mac_addr, wifi_dev->dev_addr, ETH_ALEN);
  496.         return 0;
  497. }


  498. /**
  499. * @brief  获取WIFI连接的统计信息(信号强度...)
  500. * @param  pStats : 指向station_info的指针
  501. * @param  mac : 指向需要获取的station的地址
  502. */
  503. int wifi_get_stats(uint8_t *mac,struct station_info *sinfo)
  504. {
  505.         int ret = -1;
  506.         moal_private *priv;
  507.        
  508.         priv = (moal_private *)wifi_dev->ml_priv;
  509.         if(wifi_dev->cfg80211_ops && wifi_dev->cfg80211_ops->get_station)
  510.         {
  511.                 ret = wifi_dev->cfg80211_ops->get_station(priv->wdev->wiphy, wifi_dev, mac,sinfo);

  512.         }else
  513.                 p_err("%s not support", __FUNCTION__);
  514.        
  515.         return ret;
  516. }

  517. /**
  518. * @brief  配置省电模式,在保持连接的情况下可达到很可观省电效果
  519. *                省电模式下的耗电量由数据收发量决定
  520. *                此外用户可以配置更加细节的电源管理参数,比如DTIM间隔
  521. *                一般情况下使用此函数已经够用
  522. *
  523. * @param  power_save_level : 取值 0,1,2;
  524. *        0代表关闭省电模式(CAM)
  525. *        1采用DTIM省电方式
  526. *    2采用INACTIVITY省电方式
  527. * @param  mac : 指向需要获取的station的地址
  528. */
  529. int wifi_power_cfg(uint8_t power_save_level)
  530. {
  531.         int ret = -1;
  532.         moal_private *priv;

  533.         priv = (moal_private *)wifi_dev->ml_priv;
  534.         if(priv->bss_role == MLAN_BSS_ROLE_UAP)
  535.         {
  536.                 if(wifi_dev->netdev_ops && wifi_dev->netdev_ops->ndo_do_ioctl)
  537.                 {
  538.                         struct iwreq *wrq = (struct iwreq *)mem_calloc(sizeof(struct iwreq), 1);
  539.                         if(wrq)
  540.                         {
  541.                                 /*
  542.                                 if(sleep)
  543.                                 {
  544.                                         deep_sleep_para param;
  545.                                         memset(¶m, 0, sizeof(deep_sleep_para));
  546.                                         wrq->u.data.pointer = ¶m;
  547.                                         param.subcmd = UAP_DEEP_SLEEP;
  548.                                         param.action = MLAN_ACT_SET;
  549.                                         param.deep_sleep = TRUE;
  550.                                         param.idle_time = 1000;
  551.                                         ret = wifi_dev->netdev_ops->ndo_do_ioctl(wifi_dev, (void*)wrq, UAP_IOCTL_CMD);
  552.        
  553.                                 }else
  554.                                 */
  555.                                 {
  556.                                         mlan_ds_ps_mgmt ps_mgmt;

  557.                                         memset(&ps_mgmt, 0, sizeof(mlan_ds_ps_mgmt));
  558.                                         wrq->u.data.pointer = &ps_mgmt;

  559.                                         ps_mgmt.flags = PS_FLAG_PS_MODE;
  560.                                         if(power_save_level == 0)
  561.                                                 ps_mgmt.ps_mode = PS_MODE_DISABLE;
  562.                                         else if(power_save_level == 1)
  563.                                                 ps_mgmt.ps_mode = PS_MODE_PERIODIC_DTIM;
  564.                                         else if(power_save_level == 2)
  565.                                                 ps_mgmt.ps_mode = PS_MODE_INACTIVITY;
  566.                                         else
  567.                                                 ps_mgmt.ps_mode = PS_MODE_DISABLE;
  568.                                        
  569.                                         ret = wifi_dev->netdev_ops->ndo_do_ioctl(wifi_dev, (void*)wrq, UAP_POWER_MODE);
  570.                                 }

  571.                                 mem_free(wrq);
  572.                         }
  573.                 }
  574.         }

  575.         if(priv->bss_role == MLAN_BSS_ROLE_STA)
  576.         {
  577.                 if(wifi_dev->cfg80211_ops && wifi_dev->cfg80211_ops->set_power_mgmt)
  578.                 {
  579.                         bool enable;
  580.                         if(power_save_level == 0)
  581.                                 enable = FALSE;
  582.                         else
  583.                                 enable = TRUE;
  584.                         ret = wifi_dev->cfg80211_ops->set_power_mgmt(priv->wdev->wiphy, wifi_dev,enable, 0);
  585.                 }
  586.         }
  587.        
  588.         return ret;
  589. }



  590. /**
  591. * @brief  这里不再提供WIFI事件的回调
  592. *
  593. * ap模式下请参考wlan_ops_uap_process_event函数
  594. * sta模式下请参考wlan_ops_sta_process_event函数
  595. */

  596. int event_callback(int type)
  597. {

  598.         return 0;
  599. }

  600. extern uint8_t g_mac_addr[6];


  601. /**
  602. * @brief  通过CPU_ID计算出一个随机数用于填充MAC地址的低3字节
  603. *
  604. *
  605. */
  606. int create_mac(unsigned char *mac)
  607. {
  608.         char psk[33], id[12];
  609. ……………………

  610. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
无线遥控器设计.zip (9.01 MB, 下载次数: 46)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表