MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_wlan_set_mode

Function rt_wlan_set_mode

components/drivers/wlan/dev_wlan_mgnt.c:662–812  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

660}
661
662rt_err_t rt_wlan_set_mode(const char *dev_name, rt_wlan_mode_t mode)
663{
664 rt_device_t device = RT_NULL;
665 rt_err_t err;
666 rt_int8_t up_event_flag = 0;
667 rt_wlan_dev_event_handler handler = RT_NULL;
668
669 if ((dev_name == RT_NULL) || (mode >= RT_WLAN_MODE_MAX))
670 {
671 RT_WLAN_LOG_E("Parameter Wrongful name:%s mode:%d", dev_name, mode);
672 return -RT_EINVAL;
673 }
674
675 RT_WLAN_LOG_D("%s is run dev_name:%s mode:%s%s%s", __FUNCTION__, dev_name,
676 mode == RT_WLAN_NONE ? "NONE" : "",
677 mode == RT_WLAN_STATION ? "STA" : "",
678 mode == RT_WLAN_AP ? "AP" : ""
679 );
680
681 /* find device */
682 device = rt_device_find(dev_name);
683 if (device == RT_NULL)
684 {
685 RT_WLAN_LOG_E("not find device, set mode failed! name:%s", dev_name);
686 return -RT_EIO;
687 }
688
689 MGNT_LOCK();
690 if (RT_WLAN_DEVICE(device)->mode == mode)
691 {
692 RT_WLAN_LOG_D("L:%d this device mode is set");
693 MGNT_UNLOCK();
694 return RT_EOK;
695 }
696
697 if ((mode == RT_WLAN_STATION) &&
698 (RT_WLAN_DEVICE(device)->flags & RT_WLAN_FLAG_AP_ONLY))
699 {
700 RT_WLAN_LOG_I("this device ap mode only");
701 MGNT_UNLOCK();
702 return -RT_ERROR;
703 }
704 else if ((mode == RT_WLAN_AP) &&
705 (RT_WLAN_DEVICE(device)->flags & RT_WLAN_FLAG_STA_ONLY))
706 {
707 RT_WLAN_LOG_I("this device sta mode only");
708 MGNT_UNLOCK();
709 return -RT_ERROR;
710 }
711
712 /*
713 * device == sta and change to ap, should deinit
714 * device == ap and change to sta, should deinit
715 */
716 if (((mode == RT_WLAN_STATION) && (RT_WLAN_DEVICE(device) == AP_DEVICE())) ||
717 ((mode == RT_WLAN_AP) && (RT_WLAN_DEVICE(device) == STA_DEVICE())))
718 {
719 err = rt_wlan_set_mode(dev_name, RT_WLAN_NONE);

Callers 15

wifi_debug_set_modeFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_spi_device_initFunction · 0.85
wifi_init_thread_entryFunction · 0.85

Calls 5

rt_device_findFunction · 0.85
rt_wlan_dev_initFunction · 0.85
rt_wlan_prot_attachFunction · 0.85

Tested by

no test coverage detected