title: Migrating a codeless KEXT to a codeless DEXT
body: <p>I am migrating a codeless KEXT to a codeless DEXT. I have watched the WWDC video and read much of the information on the Apple Developer site. The difficulty I am having is finding not what to do but how to get started. A nice tutorial with an example project would help.</p>
  <p>In my codeless KEXT, for 4 separate devices I have IOKitPersonalities for IOUSBDevice and IOUSBInterface for each device. The KEXT allowed me to match my devices to my &quot;driver&quot; so the Apple HID driver wouldn't grab them. I wish to do the same or something similar in the codeless DEXT.</p>
  <p>So far, I have created a DriverKit target (for a DriverKit.framework) called MyUsbDriver in an app and added a USBDriverKit.framework. That added a folder MyUsbDriver to my project with files MyUsbDriver.cpp, MyUsbDriver.iig, Info.plist and MyUsbDriver.entitlements. Here are my questions:</p>
  <ol>
  <li><p>It looks like the default subclass of IOService is OK for USB - that is the same as the IOClass from the KEXT. Is that true?</p>
  </li>
  <li><p>Is IOUSBHostInterface in DEXT-world equivalent to IOUSBInterface in KEXT-world?</p>
  </li>
  <li><p>Is IOUSBHostDevice equivalent to IOUSBDevice?</p>
  </li>
  <li><p>Do I need to do anything to the .cpp or .iig for codeless DEXT? Isn't most of my work to be done in the plist and entitlements files?</p>
  </li>
  <li><p>Do I need the USBDriverKit.framework in my Frameworks and Libraries of MyUsbDriver target?</p>
  </li>
  <li><p>Where can I find a decent example of how to complete this migration?</p>
  </li>
  </ol>
  <p>Any help would be greatly appreciated.</p>
  <p>Update:</p>
  <p>Using the example and other links in the answer I was able to get something together. I did have a &quot;Doh&quot; moment: My initial test project type was Command Line Tool and I could never get the DEXT to embed. I almost just hand-edited the pbxproj file. However, in looking at the original example USBApp from Scott Knight, I realized the project type he was using was App, In hindsight, that makes sense but at the time was confounding.</p>
  <p>Here is the info.plist I have so far to match on one of our deprecated devices:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
  &lt;plist version=&quot;1.0&quot;&gt;
  &lt;dict&gt;
      &lt;key&gt;CFBundleDevelopmentRegion&lt;/key&gt;
      &lt;string&gt;$(DEVELOPMENT_LANGUAGE)&lt;/string&gt;
      &lt;key&gt;CFBundleExecutable&lt;/key&gt;
      &lt;string&gt;$(EXECUTABLE_NAME)&lt;/string&gt;
      &lt;key&gt;CFBundleIdentifier&lt;/key&gt;
      &lt;string&gt;$(PRODUCT_BUNDLE_IDENTIFIER)&lt;/string&gt;
      &lt;key&gt;CFBundleInfoDictionaryVersion&lt;/key&gt;
      &lt;string&gt;6.0&lt;/string&gt;
      &lt;key&gt;CFBundleName&lt;/key&gt;
      &lt;string&gt;$(PRODUCT_NAME)&lt;/string&gt;
      &lt;key&gt;CFBundlePackageType&lt;/key&gt;
      &lt;string&gt;$(PRODUCT_BUNDLE_PACKAGE_TYPE)&lt;/string&gt;
      &lt;key&gt;CFBundleShortVersionString&lt;/key&gt;
      &lt;string&gt;1.0&lt;/string&gt;
      &lt;key&gt;CFBundleVersion&lt;/key&gt;
      &lt;string&gt;1&lt;/string&gt;
      &lt;key&gt;IOKitPersonalities&lt;/key&gt;
      &lt;dict&gt;
          &lt;key&gt;MyUsbDrver&lt;/key&gt;
          &lt;dict&gt;
              &lt;key&gt;CFBundleIdentifier&lt;/key&gt;
              &lt;string&gt;$(PRODUCT_BUNDLE_IDENTIFIER)&lt;/string&gt;
              &lt;key&gt;CFBundleIdentifierKernel&lt;/key&gt;
              &lt;string&gt;com.apple.kpi.iokit&lt;/string&gt;
              &lt;key&gt;IOClass&lt;/key&gt;
              &lt;string&gt;IOUserService&lt;/string&gt;
              &lt;key&gt;IOMatchCategory&lt;/key&gt;
              &lt;string&gt;com.apple.null.driver&lt;/string&gt;
              &lt;key&gt;IOProviderClass&lt;/key&gt;
              &lt;string&gt;IOUsbHostInterface&lt;/string&gt;
              &lt;key&gt;IOResourceMatch&lt;/key&gt;
              &lt;string&gt;IOKit&lt;/string&gt;
              &lt;key&gt;IOUserClass&lt;/key&gt;
              &lt;string&gt;MyUsbDrver&lt;/string&gt;
              &lt;key&gt;IOUserServerName&lt;/key&gt;
              &lt;string&gt;Home.MyUsbDrver&lt;/string&gt;
              &lt;key&gt;bConfigurationValue&lt;/key&gt;
              &lt;integer&gt;1&lt;/integer&gt;
              &lt;key&gt;bInterfaceNumber&lt;/key&gt;
              &lt;integer&gt;0&lt;/integer&gt;
              &lt;key&gt;idProduct&lt;/key&gt;
              &lt;integer&gt;2&lt;/integer&gt;
              &lt;key&gt;idVendor&lt;/key&gt;
              &lt;integer&gt;5843&lt;/integer&gt;
          &lt;/dict&gt;
      &lt;/dict&gt;
      &lt;key&gt;OSBundleUsageDescription&lt;/key&gt;
      &lt;string&gt;Codless DEXT to match on IOKit.&lt;/string&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  <p>I am not sure about IOResourceMatch - the value is IOKit, which is the direction I am trying to go.</p>
  <p>Update the Second:</p>
  <p>Progress!</p>
  <p>I ended up having to manually change the signing provisions in my pbxproj file. Disabled SIP, set up System Extension activation/deactivation in my app and did command-line signing. I found this repository to be helpful with a decent Objective-C example for the activation code - <a href="https://github.com/google/santa.git" rel="nofollow noreferrer">https://github.com/google/santa.git</a>. Everything builds and code signing seemed to be successful. Getting the fun error</p>
  <pre><code>SystemExtension &quot;Home.MyUsbDrver&quot; request did fail: Error Domain=OSSystemExtensionErrorDomain Code=8 &quot;(null)&quot;
  </code></pre>
  <p>Update 3:</p>
  <p>I checked my DEXT and app entitlements, and it looked like the app entitlements needed to be updated. This is what I have now for app:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
  &lt;plist version=&quot;1.0&quot;&gt;
  &lt;dict&gt;
      &lt;key&gt;com.apple.security.app-sandbox&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;com.apple.security.files.user-selected.read-only&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;com.apple.developer.system-extension.install&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;com.apple.developer.system-extension.uninstall&lt;/key&gt;
      &lt;true/&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>
  <p>I was missing the bottom two. Cleaned my project, built, signed again. When I tried running from Xcode, still got the error. When I ran my app from Finder, I got the system preferences dialog. After that, still the same result from Xcode, and now nothing but a flash of the app when run from Finder. I rebooted - still the same results. However, from terminal when I run systemextensionsctl -list, I get:</p>
  <pre><code>3 extension(s)
  --- com.apple.system_extension.driver_extension
  enabled active  teamID  bundleID (version)  name    [state]
          &lt;REDACTED&gt;  Home.MyUsbDrver (1.0/1) Home.MyUsbDrver [terminated waiting to uninstall on reboot]
  *   *   &lt;REDACTED&gt;  Home.MyUsbDrver (1.0/1) Home.MyUsbDrver [activated enabled]
          &lt;REDACTED&gt;  Home.MyUsbDrver (1.0/1) Home.MyUsbDrver [activated waiting to upgrade]
  </code></pre>
  <p>After a reboot I get this:</p>
  <pre><code>1 extension(s)
  --- com.apple.system_extension.driver_extension
  enabled active  teamID  bundleID (version)  name    [state]
  *   *   &lt;REDACTED&gt;  Home.MyUsbDrver (1.0/1) Home.MyUsbDrver [activated enabled]
  </code></pre>
  <p>So, it looks like my system extension is in place, but I am actually not sure why since I just did a fresh reboot and have not run my app.</p>
  <p>Update 4:</p>
  <p>I figured out the problem with my entitlements was just the format of the file. I changed it in TextEdit and I can now communicate with my device. Here is what I ended up with:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
  &lt;plist version=&quot;1.0&quot;&gt;
  &lt;dict&gt;
      &lt;key&gt;com.apple.developer.driverkit&lt;/key&gt;
      &lt;true/&gt;
      &lt;key&gt;com.apple.developer.driverkit.transport.usb&lt;/key&gt;
      &lt;array&gt;
          &lt;dict&gt;
              &lt;key&gt;idVendor&lt;/key&gt;
              &lt;integer&gt;VID0&lt;/integer&gt;
              &lt;key&gt;idProductArray&lt;/key&gt;
              &lt;array&gt;
                  &lt;integer&gt;PID0&lt;/integer&gt;
                  &lt;integer&gt;PID1&lt;/integer&gt;
                  &lt;integer&gt;PID2&lt;/integer&gt;
                  &lt;integer&gt;PID3&lt;/integer&gt;
                  &lt;integer&gt;PID4&lt;/integer&gt;
              &lt;/array&gt;
          &lt;/dict&gt;
      &lt;/array&gt;
      &lt;key&gt;com.apple.security.app-sandbox&lt;/key&gt;
      &lt;true/&gt;
  &lt;/dict&gt;
  &lt;/plist&gt;
  </code></pre>