title: Enable monitoring mode for RTL8188CUS via USB on Raspbian
body: <p>I am trying to enable monitoring mode for a USB wifi dongle with the RTL8188CUS chipset on a raspberry pi model b+ (or any raspberry pi for that matter).</p>
  
  <pre><code>$ lsusb
  Bus 001 Device 005: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter
  $ sudo iwconfig wlan0 mode monitor
  Error for wireless request "Set Mode" (8B06) :
      SET failed on device wlan0 ; Invalid argument.
  </code></pre>
  
  <p>According to <a href="https://github.com/raspberrypi/linux/issues/369" rel="noreferrer">github/raspberrypi/linux/issues/369</a>, you need to enable the rtlwifi/rtl8192cu kernel module that is included with the kernel distribution but not compiled.  This requires minor modifications to some files as diff'ed below in 'STEP 2'. </p>
  
  <p>The USB issue mentioned in that thread has been resolved as of 4.1.6+, so the rtlwifi driver should work.</p>
  
  <p>Steps to recreate on a fresh raspberry pi (model B+)...</p>
  
  <p><strong>STEP 0: Update existing modules and kernel to latest</strong></p>
  
  <pre><code>$ sudo apt-get update
  $ sudo rpi-update
  $ uname -a
  Linux raspberrypi 4.1.7+ #815 PREEMPT Thu Sep 17 17:59:24 BST 2015 armv6l GNU/Linux
  </code></pre>
  
  <p><strong>STEP 1:  Get the raspbian kernel source and add missing dependencies</strong></p>
  
  <pre><code>$ git clone --depth=1 https://github.com/raspberrypi/linux
  $ sudo apt-get install bc lshw
  </code></pre>
  
  <p><strong>STEP 2:  Enable the rtlwifi (kernel) drivers for RTL8188CUS (RTL8192)</strong></p>
  
  <pre><code>edit linux/drivers/net/wireless/Kconfig
  -#source "drivers/net/wireless/rtlwifi/Kconfig"
  -source "drivers/net/wireless/rtl8192cu/Kconfig"
  +source "drivers/net/wireless/rtlwifi/Kconfig"
  +#source "drivers/net/wireless/rtl8192cu/Kconfig"
  
  (Wheezy) edit linux/drivers/net/wireless/Makefile
  -#obj-$(CONFIG_RTLWIFI)         += rtlwifi/
  +obj-$(CONFIG_RTLWIFI)          += rtlwifi/
  
  (Jessie) edit linux/drivers/net/wireless/realtek/Makefile
  -#obj-$(CONFIG_RTLWIFI)         += rtlwifi/
  +obj-$(CONFIG_RTLWIFI)          += rtlwifi/
  </code></pre>
  
  <p><strong>STEP 3: Compile and install kernel (took many hours)</strong></p>
  
  <p>Summarized from <a href="https://www.raspberrypi.org/documentation/linux/kernel/building.md" rel="noreferrer">kernel building documentation</a> .</p>
  
  <pre><code>$ cd linux
  $ KERNEL=kernel
  $ make bcmrpi_defconfig
  
  $ make zImage modules dtbs
  $ sudo make modules_install
  $ sudo cp arch/arm/boot/dts/*.dtb /boot/
  $ sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
  $ sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
  $ sudo scripts/mkknlimg arch/arm/boot/zImage /boot/$KERNEL.img
  </code></pre>
  
  <p><strong>STEP 4: Reboot</strong></p>
  
  <pre><code>$ sudo reboot
  </code></pre>
  
  <p><strong>STEP 5: Check that the rtlwifi/rtl8192cu module is loaded</strong></p>
  
  <pre><code>$ lsmod | fgrep rtl8192cu
  rtl8192cu             100806  0 
  rtl_usb                14781  1 rtl8192cu
  rtl8192c_common        72091  1 rtl8192cu
  rtlwifi               101122  3 rtl_usb,rtl8192c_common,rtl8192cu
  mac80211              623281  3 rtl_usb,rtlwifi,rtl8192cu
  $
  $ lshw
    *-network:0
         description: Ethernet interface
         physical id: 1
         bus info: usb@1:1.3
         logical name: wlan0
         serial: 00:0b:81:94:e9:a3
         capabilities: ethernet physical
         configuration: broadcast=yes driver=rtl8192cu driverversion=4.1.7+ firmware=N/A link=no multicast=yes
  </code></pre>
  
  <p><strong>STEP 6: Try to activate monitoring mode</strong></p>
  
  <pre><code>$ sudo iwconfig wlan0 mode monitor
  Error for wireless request "Set Mode" (8B06) :
      SET failed on device wlan0 ; Operation not supported.
  </code></pre>
  
  <p>What did i miss?<br>
  Issue 369 seems to indicate that it can work with the rtlwifi driver?</p>