Failed to perform Wi-Fi scan, returned error code 16

I developed a program to connect to Wi-Fi using the CoreWLAN API.

First, I need to scan for SSIDs.

However, when I call the scanning function, the scan fails occasionally.

Failed to perform Wi-Fi scan, returned error code 16, will try again in 200 ms
took 2.0468 seconds, returned error [16, com.apple.wifi.apple80211API.error, 'Resource busy']

I need to retry several times to succeed, which makes the process of connecting to Wi-Fi relatively slow.

I want to know the reason of this error.

2024-08-06 18:24:13.090634+0800 0x86f393   Default     0x0                  158    0    airportd: (IO80211) [com.apple.WiFiManager:] Info: <airport[158]> -[CWXPCSubsystem performScanWithChannelList:ssidList:legacyScanSSID:dwellTimeOverride:interfaceName:scanParametersOverride:allowDuringAWDLRealTimeMode:connection:scannedChannels:error:]: Failed to perform Wi-Fi scan, returned error code 16, will try again in 200 ms
2024-08-06 18:24:13.295896+0800 0x86f393   Default     0x0                  158    0    airportd: (IO80211) Apple80211IOCTLSetWrapper:5093 @[3748838.819485] ifname['en0'] IOUC type 10/'APPLE80211_IOC_SCAN_REQ', len[5456] return 16/0x00000010
2024-08-06 18:24:13.295929+0800 0x86f393   Default     0x0                  158    0    airportd: (IO80211) [com.apple.WiFiManager:] Info: <airport[158]> -[CWXPCSubsystem performScanWithChannelList:ssidList:legacyScanSSID:dwellTimeOverride:interfaceName:scanParametersOverride:allowDuringAWDLRealTimeMode:connection:scannedChannels:error:]: Failed to perform Wi-Fi scan, returned error code 16, will try again in 200 ms
2024-08-06 18:24:13.498811+0800 0x86f393   Default     0x0                  158    0    airportd: (IO80211) [com.apple.WiFiManager:] Info: <airport[158]> -[CWXPCSubsystem performScanWithChannelList:ssidList:legacyScanSSID:dwellTimeOverride:interfaceName:scanParametersOverride:allowDuringAWDLRealTimeMode:connection:scannedChannels:error:]: Failed to perform Wi-Fi scan, returned error code 16
2024-08-06 18:24:13.499112+0800 0x86f393   Default     0x0                  158    0    airportd: (IO80211) [com.apple.WiFiManager:] Scan: <airport[158]> -[CWXPCConnection __performScanWithChannelSubset:ssidList:legacyScanSSID:includeHiddenNetworks:mergeScanResults:maxAge:maxMissCount:maxWakeCount:maxAutoJoinCount:interfaceName:waitForWiFi:waitForBluetooth:token:priority:scanParametersOverride:allowDuringAWDLRealTimeMode:reply:]_block_invoke: [575EE] WIFI_REQ_SCAN (exit)
2024-08-06 18:24:13.499318+0800 0x86f7a7   Default     0x0                  158    0    airportd: (IO80211) [com.apple.WiFiManager:] AutoJoin: <airport[158]> Failed cache-assisted scan request for wifihelper with channels {(
    <CWChannel: 0x138b236f0> [channelNumber=1(2GHz), channelWidth={20MHz}, active],
    <CWChannel: 0x138b8f880> [channelNumber=6(2GHz), channelWidth={20MHz}, active],
    <CWChannel: 0x138bee730> [channelNumber=11(2GHz), channelWidth={20MHz}, active],
    <CWChannel: 0x138b77590> [channelNumber=2(2GHz), channelWidth={20MHz}, active],
    <CWChannel: 0x138bb7e40> [channelNumber=3(2GHz), channelWidth={20MHz}, active],
    <CWChannel: 0x138b51290> [channelNumber=4(2GHz), channelWidth={20MHz}, active]
)}, took 2.0468 seconds, returned error [16, com.apple.wifi.apple80211API.error, 'Resource busy']

Answered by DTS Engineer in 799196022

I need to retry several times to succeed, which makes the process of connecting to Wi-Fi relatively slow.

Why?

I want to know the reason of this error.

Depending on the APIs involved it could be a few different things:

  • The underlying controller only allows one life scan to be occurring at a time, so additional requests fail with EBUSY ("16") and receive the cached data.

  • CoreWLAN enforces a 10s wait between life scan requests. Requests more frequent than that will fail with EBUSY and receive the cached results.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

I need to retry several times to succeed, which makes the process of connecting to Wi-Fi relatively slow.

Why?

I want to know the reason of this error.

Depending on the APIs involved it could be a few different things:

  • The underlying controller only allows one life scan to be occurring at a time, so additional requests fail with EBUSY ("16") and receive the cached data.

  • CoreWLAN enforces a 10s wait between life scan requests. Requests more frequent than that will fail with EBUSY and receive the cached results.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Failed to perform Wi-Fi scan, returned error code 16
 
 
Q