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

Function rt_wlan_start_ap

components/drivers/wlan/dev_wlan_mgnt.c:1219–1288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1217}
1218
1219rt_err_t rt_wlan_start_ap(const char *ssid, const char *password)
1220{
1221 rt_err_t err = RT_EOK;
1222 int ssid_len = 0;
1223 struct rt_wlan_info info;
1224 struct rt_wlan_complete_des *complete;
1225 rt_uint32_t set = 0, recved = 0;
1226
1227 if (_ap_is_null())
1228 {
1229 return -RT_EIO;
1230 }
1231 if (ssid == RT_NULL) return -RT_EINVAL;
1232
1233 rt_memset(&info, 0, sizeof(struct rt_wlan_info));
1234 RT_WLAN_LOG_D("%s is run ssid:%s password:%s", __FUNCTION__, ssid, password);
1235 if (password)
1236 {
1237 info.security = SECURITY_WPA2_AES_PSK;
1238 }
1239 ssid_len = rt_strlen(ssid);
1240 if (ssid_len > RT_WLAN_SSID_MAX_LENGTH)
1241 {
1242 RT_WLAN_LOG_E("ssid is to long! len:%d", ssid_len);
1243 }
1244
1245 /* copy info */
1246 rt_memcpy(&info.ssid.val, ssid, ssid_len);
1247 info.ssid.len = ssid_len;
1248 info.channel = 6;
1249 info.band = RT_802_11_BAND_2_4GHZ;
1250
1251 /* Initializing events that need to wait */
1252 MGNT_LOCK();
1253 /* create event wait complete */
1254 complete = rt_wlan_complete_create("start_ap");
1255 if (complete == RT_NULL)
1256 {
1257 MGNT_UNLOCK();
1258 return -RT_ENOMEM;
1259 }
1260
1261 /* start ap */
1262 err = rt_wlan_start_ap_adv(&info, password);
1263 if (err != RT_EOK)
1264 {
1265 rt_wlan_complete_delete(complete);
1266 RT_WLAN_LOG_I("start ap failed!");
1267 MGNT_UNLOCK();
1268 return err;
1269 }
1270
1271 /* Initializing events that need to wait */
1272 set |= 0x1 << RT_WLAN_DEV_EVT_AP_START;
1273 set |= 0x1 << RT_WLAN_DEV_EVT_AP_STOP;
1274 /* Check whether there is a waiting event */
1275 rt_wlan_complete_wait(complete, set, RT_WLAN_START_AP_WAIT_MS, &recved);
1276 rt_wlan_complete_delete(complete);

Callers 1

wifi_apFunction · 0.85

Calls 8

_ap_is_nullFunction · 0.85
rt_memsetFunction · 0.85
rt_strlenFunction · 0.85
rt_memcpyFunction · 0.85
rt_wlan_complete_createFunction · 0.85
rt_wlan_start_ap_advFunction · 0.85
rt_wlan_complete_deleteFunction · 0.85
rt_wlan_complete_waitFunction · 0.85

Tested by

no test coverage detected