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

Function rt_wlan_connect

components/drivers/wlan/dev_wlan_mgnt.c:879–976  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

877#endif
878
879rt_err_t rt_wlan_connect(const char *ssid, const char *password)
880{
881 rt_err_t err = RT_EOK;
882 int ssid_len = 0;
883 struct rt_wlan_info info;
884 struct rt_wlan_complete_des *complete;
885 rt_uint32_t set = 0, recved = 0;
886
887 /* sta dev Can't be NULL */
888 if (_sta_is_null())
889 {
890 return -RT_EIO;
891 }
892 RT_WLAN_LOG_D("%s is run ssid:%s password:%s", __FUNCTION__, ssid, password);
893 if (ssid == RT_NULL)
894 {
895 RT_WLAN_LOG_E("ssid is null!");
896 return -RT_EINVAL;
897 }
898 ssid_len = rt_strlen(ssid);
899 if (ssid_len > RT_WLAN_SSID_MAX_LENGTH)
900 {
901 RT_WLAN_LOG_E("ssid is to long! ssid:%s len:%d", ssid, ssid_len);
902 return -RT_EINVAL;
903 }
904
905 if ((rt_wlan_is_connected() == RT_TRUE) &&
906 (rt_strcmp((char *)&_sta_mgnt.info.ssid.val[0], ssid) == 0))
907 {
908 RT_WLAN_LOG_I("wifi is connect ssid:%s", ssid);
909 return RT_EOK;
910 }
911 /* get info from cache */
912 INVALID_INFO(&info);
913 MGNT_LOCK();
914
915 rt_memcpy(&info.ssid.val[0],ssid,rt_strlen(ssid));
916 info.ssid.len = rt_strlen(ssid);
917
918#ifdef RT_WLAN_JOIN_SCAN_BY_MGNT
919 err = rt_wlan_register_event_handler(RT_WLAN_EVT_SCAN_REPORT,rt_wlan_join_scan_callback,&info);
920 if(err != RT_EOK)
921 {
922 LOG_E("Scan register user callback error:%d!\n",err);
923 return err;
924 }
925
926 err = rt_wlan_scan_with_info(&info);
927 if(err != RT_EOK)
928 {
929 LOG_E("Scan with info error:%d!\n",err);
930 return err;
931 }
932
933 if (info.channel <= 0)
934 {
935 RT_WLAN_LOG_W("not find ap! ssid:%s,info.ssid.len=%d", ssid,info.ssid.len);
936 MGNT_UNLOCK();

Callers 5

wifi_joinFunction · 0.85
rt_wlan_auto_connect_runFunction · 0.85
rt_wlan_device_connetctFunction · 0.85
wifi_spi_device_initFunction · 0.85
rt_wlan_device_connetctFunction · 0.85

Calls 11

_sta_is_nullFunction · 0.85
rt_strlenFunction · 0.85
rt_wlan_is_connectedFunction · 0.85
rt_strcmpFunction · 0.85
rt_memcpyFunction · 0.85
rt_wlan_scan_with_infoFunction · 0.85
rt_wlan_complete_createFunction · 0.85
rt_wlan_connect_advFunction · 0.85
rt_wlan_complete_deleteFunction · 0.85
rt_wlan_complete_waitFunction · 0.85

Tested by

no test coverage detected