Disable peripherals on macOS programmatically

I know with Disk Arbitration framework, I can use DARegisterDiskMountApprovalCallback to prevent external disks from mounting. The disks includes thumb drive, external hard disk, etc., but there are many types of peripherals out there, like a usb wireless receiver or a USB ethernet adapter. Is there any other framework for us to use to enable/disable peripherals based on their I/O Registry properties? Thanks!

Replies

Let me make my question more specific. I'd like to be able to enable/disable built-in/external network adapter(ethernet or Wi-Fi), built-in/external bluetooth adapter, etc. Is there any general method to deal with individual hardware just like Windows? Thanks!

On the networking front, it depends on what you mean by “disable”:

  • If want to prevent the hardware from showing up at all, you may be able to do that at the I/O Kit level. The typical approach is to create an I/O Kit driver that matches against the hardware more tightly than the built-in drivers, and then explicitly avoids publishing a network interface.

  • If you want to disabling the resulting network interface, you can do that using the System Configuration framework.

Both approaches have present significant challenges.

Share and Enjoy

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

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

Hey, a bit late but I don't get the System Configuration API completely. How do I use that to disable e.g. "en0"? I got the Network Interface by using "SCNetworkInterfaceCopyAll()" and iterated over the interfaces. How do I check the current status (if it's enabled or disabled)? By using "SCNetworkInterfaceGetConfiguration()"? And do I set that by using "SCNetworkInterfaceSetConfiguration()"? The response for my NetworkInterfaces is always nil, when I try to get the Configuration by using "SCNetworkInterfaceGetConfiguration()".

I don't get the System Configuration API completely.

I recommend that you start with the System Configuration Programming Guidelines. Despite it being in the Documentation Archive, it’s the best explanation of SCF concepts that you’re likely to find.

If you have specific questions after that, please put them in a new thread. Tag it with System Configuration so that I see it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"