Parameter error with startIBSSModeWithSSID

I'm trying to create an adhoc network but whenever I execute my script I'm getting an error saying:


"The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3900.)"



My code looks like this:


import Foundation
import CoreWLAN;
import ObjectiveC;

var ssid = NSData();
var security = CWIBSSModeSecurity.None;
var channel = Int(11);
var password = NSString();
var error: NSError?

var iface = CWWiFiClient.sharedWiFiClient().interface();
println(iface.interfaceName);

var ibss = iface.startIBSSModeWithSSID(nil, security: CWIBSSModeSecurity.WEP104, channel: 11, password: password as String, error: &error);

if error != nil{
    println(error?.localizedDescription);
}

var loop = NSRunLoop();
NSRunLoop.currentRunLoop().run();



Any idea as to what I'm doing wrong ?

Answered by DTS Engineer in 34703022

Well, there's nothing of interest in the system log, so I tried running your code. I got the same error but, after poking around a bit, I managed to get things working. Here's what I ended up with.

import Foundation 
import CoreWLAN 

var error: NSError? 

let iface = CWWiFiClient.sharedWiFiClient().interface() 
println(iface.interfaceName) 

let success = iface.startIBSSModeWithSSID(
    "Test".dataUsingEncoding(NSUTF8StringEncoding),
    security: CWIBSSModeSecurity.WEP104,
    channel: 11,
    password: "HelloCruelWorld",
    error: &error
)

if !success { 
    println(error?.localizedDescription) 
} else {
    NSRunLoop.currentRunLoop().run()
}

With reference to your line numbers:

  • You have a lot of unnecessary semicolons (-:

  • Line 3 is a bit weird and definitely unnecessary.

  • Line 5 is unneeded because you never reference

    ssid
    .
  • Likewise for

    security
    on line 6.
  • Likewise for

    channel
    on line 7.
  • Line 8 is definitely a problem; you can't create a

    .WEP104
    network without supplying a password.
  • In lines 11 and 14, you should use

    let
    not
    var
    because you don't change the values afterwards.
  • In line 14 I changed

    ibss
    to
    success
    , which more accurately reflects its role.
  • In line 16, Cocoa convention says that you shouldn't test

    error
    without first testing success (fortunately this class of problem will go away with Swift 2's shiny new error handling mechanism).
  • Line 20 is unnecessary.

None of this actually fixed the problem )-:

After some more poking around I found that the issue was the SSID parameter. It seems that, despite what it says in the header comments,

-startIBSSModeWithSSID:xxx
really doesn't like nil here. Once I started passing in a real name, things just worked.

Please file a bug against the header commons, then post your bug number here, just for the record.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

The operation couldn’t be completed. (com.apple.wifi.apple80211API.error error -3900.)

This is the AirPort equivalent of

EINVAL
or
paramErr
, a general-purpose error saying that the caller's parameters are ouf of whack. That doesn't make it easy to track down the source of the error.

Two questions:

  • Do you see anything in the system log when you get this error?

  • It looks like you're testing this in a Foundation tool. What happens if you test with an app?

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for the input. When i try to run the script I get the following output in the system logs


7/30/15 10:49:02.495 AM com.apple.debugserver-@(#)PROGRAM:debugserver  PROJECT:debugserver-330.0.44
[13653]: debugserver-@(#)PROGRAM:debugserver  PROJECT:debugserver-330.0.44
for x86_64.
7/30/15 10:49:02.496 AM com.apple.debugserver-@(#)PROGRAM:debugserver  PROJECT:debugserver-330.0.44
[13653]: Got a connection, waiting for process information for launching or attaching.
7/30/15 10:49:02.000 AM kernel[0]: warning: debugserver(13653) performed out-of-band resume on STAdHoc(13652)
7/30/15 10:49:02.778 AM com.apple.debugserver-@(#)PROGRAM:debugserver  PROJECT:debugserver-330.0.44
[13653]: Attach succeeded, ready to debug.
7/30/15 10:49:04.714 AM Xcode[13581]: [MT] DVTAssertions: Warning in /SourceCache/IDEFrameworks/IDEFrameworks-7702/IDEKit/Workspace/IDEToolbarStopButtonViewController.m:259
Details:  Stop Button failed to cancel tracker:
     <IDEExecutionOperationTracker 0x7f9d5a3fa680 Run "STAdHoc" isFinished: YES>
     canceled: Hard Cancel
              <IDEExecutionRunnableTracker 0x7f9d5a7431a0 (null) isFinished: YES>
         canceled: Hard Cancel
         is _finishedRunning
     operationFinished: YES
         <DVTOperationGroup 0x7f9d5a3f84f0 not blocking>         suboperations:
              <IDEBuildOperationGroup 0x7f9d597375a0 not blocking>             suboperations:
                  <IDEBuildOperation 0x7f9d5a3bf670 not blocking>
                  <DVTOperation 0x7f9d5a738270 not blocking>
              <DVTOperationGroup 0x7f9d5a745240 not blocking>             suboperations:
                  <DVTOperationGroup 0x7f9d5a744520 not blocking>                 suboperations:
                      <DVTOperation 0x7f9d5a743d40 not blocking>
                      <IDERunOperation 0x7f9d5a743300 not blocking>
                      <IDESchemeActionResultOperation 0x7f9d5a7436d0 not blocking>
                  <DVTOperation 0x7f9d5a745f20 not blocking>
Object:   <IDEToolbarStopButtonViewController: 0x7f9d59e97d30>
Method:   -_stopLaunchSession:
Thread:   <NSThread: 0x7f9d53d39520>{number = 1, name = main}
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide.



As for trying it out as an app, I'm not exactly sure what you mean (I'm a web developer attempting to hack a Swift script). When i created this project in Xcode I created a Command Line Tool. If you were referring to creating a Cocoa Application I tried that as well and I still get the same error. If this isn't what you were referring to would you please provide more detail? Thanks!

Accepted Answer

Well, there's nothing of interest in the system log, so I tried running your code. I got the same error but, after poking around a bit, I managed to get things working. Here's what I ended up with.

import Foundation 
import CoreWLAN 

var error: NSError? 

let iface = CWWiFiClient.sharedWiFiClient().interface() 
println(iface.interfaceName) 

let success = iface.startIBSSModeWithSSID(
    "Test".dataUsingEncoding(NSUTF8StringEncoding),
    security: CWIBSSModeSecurity.WEP104,
    channel: 11,
    password: "HelloCruelWorld",
    error: &error
)

if !success { 
    println(error?.localizedDescription) 
} else {
    NSRunLoop.currentRunLoop().run()
}

With reference to your line numbers:

  • You have a lot of unnecessary semicolons (-:

  • Line 3 is a bit weird and definitely unnecessary.

  • Line 5 is unneeded because you never reference

    ssid
    .
  • Likewise for

    security
    on line 6.
  • Likewise for

    channel
    on line 7.
  • Line 8 is definitely a problem; you can't create a

    .WEP104
    network without supplying a password.
  • In lines 11 and 14, you should use

    let
    not
    var
    because you don't change the values afterwards.
  • In line 14 I changed

    ibss
    to
    success
    , which more accurately reflects its role.
  • In line 16, Cocoa convention says that you shouldn't test

    error
    without first testing success (fortunately this class of problem will go away with Swift 2's shiny new error handling mechanism).
  • Line 20 is unnecessary.

None of this actually fixed the problem )-:

After some more poking around I found that the issue was the SSID parameter. It seems that, despite what it says in the header comments,

-startIBSSModeWithSSID:xxx
really doesn't like nil here. Once I started passing in a real name, things just worked.

Please file a bug against the header commons, then post your bug number here, just for the record.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I can't thank you enough for the time and detailed description you put together for me. Not only did you fix my problem but I learned a lot in the process!

Parameter error with startIBSSModeWithSSID
 
 
Q