I use my device as headless as a home server and as a jump box. From past quite some time I was noticing that my Raspberry Pi was not accessible over the network after some period of in-activity. And since it is headless, the only way to get the network back was either take out the USB Wireless adapter or Reboot the Pi (through the power switch). I chose to take out the adapter and reseat it. However, this was causing my RPi to reboot also, may be because in the process the power connector was getting disturbed. I will revisit this point later.
In order to switch off the power saving for my wireless device I tried
$ sudo iwconfig wlan0 power off Error for wireless request "Set Power Management" (8B2C) : SET failed on device wlan0 ; Operation not permitted.
I am using NetGear USB wireless adapter and it load the kernel module 8192cu. Checking
$ cat /sys/module/8192cu/parameters/rtw_power_mgnt 1
I realized that the power saving is still on (1 indicates minimum power saving). So I created a module config file as below to permanently set the power saving to 0 and rebooted the RPi.
$ sudo vi /etc/modprobe.d/8192cu.conf # Disable the power management during boot - Ajitabh options 8192cu rtw_power_mgnt=0 $ sudo reboot
Checking again confirmed that the power management has been disabled.
$ cat /sys/module/8192cu/parameters/rtw_power_mgnt 0